Prompt
How to send email from Cloudflare Workers
Latest observation
You generally can’t send raw SMTP email directly from Cloudflare Workers because Workers run in a serverless, edge environment and don’t support opening arbitrary TCP sockets to SMTP servers.
Common ways to send email from a Worker
1) Use an email API provider
This is the most common approach.
Popular options:
- Resend
- SendGrid
- Mailgun
- Postmark
- Amazon SES via HTTP API
In your Worker, call their HTTPS API with fetch().
Example with a generic HTTP email API:
export default {
async fetch(request, env) {
const res = await fetch("https://api.example.com/send-email", {
method: "POST",
headers: {
"Authorization": `Bearer ${env.EMAIL_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
from: "no-reply@yourdomain.com",
to: "user@example.com",
subject: "Hello from Cloudflare Workers",
text: "This was sent from a Worker!",
}),
});
return new Response(await res.text(), { status: res.status });
}
}
Store the API key as a Worker secret:
wrangler secret put EMAIL_API_KEY
2) Use Cloudflare Email Routing + a backend
Cloudflare Email Routing receives mail, but it’s not for sending mail from Workers. If you need outgoing mail, pair Workers with an external mail service.
3) Use an email service through an SMTP relay outside Workers
If you must use SMTP, run a small backend somewhere else that your Worker calls over HTTPS, and that backend sends the SMTP email.
Best practice
For Workers, the best pattern is:
Worker → HTTPS email API → email delivered
This is simple, secure, and works well in serverless environments.
Important notes
- Don’t put API keys directly in your code.
- Verify sender domains with your email provider.
- Be aware of rate limits and anti-spam rules.
If you want, I can give you a complete Cloudflare Worker example using Resend, SendGrid, or Postmark.
Observation history
Unlock observation history
Create a free Obsurfable account to unlock historical responses, model comparisons, and deeper brand intelligence.
How did Obsurfable measure this prompt?
Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.
Which AI systems does Obsurfable collect answers from?
OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, and Meta AI.