Inbound email routing to Workers plus outbound sending via MailChannels. Process incoming mail with code and send transactional email from the same network — no separate email service needed for basic flows.
Email Routing intercepts inbound email at Cloudflare's edge and routes it to a Worker for processing. Your Worker receives the raw email (headers, body, attachments) and can parse it, store it in R2, write to D1, trigger a Queue, or forward it to another address.
For outbound email, Cloudflare partnered with MailChannels to allow Workers to send transactional email without managing SMTP infrastructure. You make an HTTP POST from your Worker to MailChannels' API with your domain's SPF/DKIM configured to authorise Cloudflare.
This isn't a replacement for SendGrid or Postmark at scale. It's the right answer for "I have a domain on Cloudflare and I need to receive contact form submissions and send confirmation emails without adding another service."
A Worker with an email() handler receives inbound messages. Parse headers, extract the body, and route the content wherever it needs to go.
export default { async email(message, env, ctx) { const from = message.from; const subject = message.headers.get("subject"); // Store in D1 await env.DB.prepare( "INSERT INTO inbox (sender, subject) VALUES (?, ?)" ).bind(from, subject).run(); // Forward to a real mailbox await message.forward("[email protected]"); } };
Send transactional email from a Worker by POSTing to the MailChannels API. Configure SPF and DKIM on your domain to authorise sending.
// Send email via MailChannels const resp = await fetch("https://api.mailchannels.net/tx/v1/send", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ personalizations: [{ to: [{ email: "[email protected]" }] }], from: { email: "[email protected]", name: "Your App" }, subject: "Welcome", content: [{ type: "text/plain", value: "Thanks for signing up." }], }), });
Cloudflare's free MailChannels partnership has changed. Check current docs for the latest outbound sending options — you may need MailChannels' paid tier or an alternative like Resend.
Cloudflare handles routing; you handle deliverability. Misconfigured DNS records mean your emails land in spam.
Large attachments consume Worker memory. For emails with large files, forward to a real mailbox or stream attachments to R2.