Skip to content

Email Triggers

Email triggers allow you to execute your Microfn functions by sending emails to a unique, auto-generated email address for your workspace. This is perfect for email-based automation, processing notifications, and converting emails into actionable tasks.

  1. Enable the email trigger for your workspace to get a unique email address.
  2. Send an email to this address.
  3. Microfn receives the email and calls your function’s exported email() handler.
  4. The parsed email payload is delivered to email(data) so you can orchestrate any follow-up logic.

You can enable the email trigger for your workspace in the dashboard:

  1. Navigate to your workspace.
  2. Go to Settings → Triggers.
  3. Click Enable Email Trigger.
  4. Copy the generated email address (e.g., ws-abc123xyz@mail.microfn.dev).

Your function will now be triggered by any email sent to this address.

Email trigger UI showing the enable toggle and unique Microfn email address

Email events call your exported email(data) handler. Emails are no longer provided on main({ input }), so use this dedicated function to work with the raw message. The payload contains the parsed email details and matches the following shape:

interface EmailEvent {
email: {
body?: string; // Plain text body content
from: string; // Sender's email address
rawSize: number; // Size of the original message in bytes
subject?: string; // Email subject line
timestamp: string; // ISO timestamp when received
to: string; // Recipient (your trigger address)
};
}
{
"email": {
"body": "hai al",
"from": "mail202509@d.pn",
"rawSize": 6386,
"subject": "herroooo",
"timestamp": "2025-09-20T07:46:14.515Z",
"to": "fn-cdmixwn7kw7p@mail.microfn.dev"
}
}

Note: Email headers are not included in the payload that reaches email(data).

Export both main (for manual or HTTP-triggered invocations) and email to react to incoming messages. The example below logs every email and returns a greeting from the default main handler.

// Welcome to Microfn!
// This is a serverless function that runs in the cloud.
// Export a main function that takes { input: data } and returns any value.
// Strings/numbers are returned as-is, objects/arrays are JSON serialized.
export async function main({ input }) {
return {
message: "Hello from Microfn!",
timestamp: new Date().toISOString(),
receivedInput: input
};
}
export async function email(data) {
// handle email trigger
console.log("email received");
console.log(data);
}