Email Service
Email for applications, workflows, and agents
Cloudflare Email Service gives your applications and agents a native way to send transactional email, receive inbound messages, and automate workflows on a global network.
Built for Agents
Programmable by default
One platform, bidirectional email
A few lines of code. Global email delivery.
Use Email Sending for outbound delivery and Email Routing for inbound handling, all from the same Workers application.
Send from Workers
Route inbound email
Enrich and orchestrate
Reply or escalate
01 02 03 04 05 06 07 08 09 10 11 12
export default { async fetch(request, env) { await env.SEND_EMAIL.send({ to: [{ email: 'user@example.com' }], from: { email: 'notifications@your-domain.com', name: 'Your App' }, subject: 'Your order has shipped', text: 'Your order #1234 has shipped and is on its way.', });
return new Response('Email sent'); },}; 01 02 03 04 05 06 07 08 09 10 11
export default { async email(message, env, ctx) { const raw = await new Response(message.raw).text();
await env.EMAIL_QUEUE.send({ from: message.from, to: message.to, raw, }); },}; 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
import { Agent, routeAgentEmail } from 'agents';import { createAddressBasedEmailResolver, type AgentEmail } from 'agents/email';import PostalMime from 'postal-mime';
export class SupportAgent extends Agent { async onEmail(email: AgentEmail) { const raw = await email.getRaw(); const parsed = await PostalMime.parse(raw);
const emails = this.state.emails || []; emails.push({ from: email.from, subject: parsed.subject, body: parsed.text, receivedAt: new Date().toISOString(), });
this.setState({ ...this.state, emails });
await this.replyToEmail(email, { fromName: 'Support Agent', body: `We received your message about "${parsed.subject}".`, }); }}
export default { async email(message, env) { await routeAgentEmail(message, env, { resolver: createAddressBasedEmailResolver('SupportAgent'), }); },};