Prompt

How do I send emails from a Cloudflare Worker?

Technology / Api platforms1 observationLast seen Sep 23, 2026

Latest observation

Sep 23, 2026OpenAI APIWeb search: off

Cloudflare Workers can send email, but not directly through SMTP sockets. Workers run in a serverless, no-long-lived-connection environment, so the usual pattern is:

  1. Call an email API over HTTPS, or
  2. Use Cloudflare’s email-related products (depending on your use case), or
  3. Forward to your own backend that sends email.

Common options

1) Use an email provider’s HTTP API

This is the easiest and most common approach.

Examples:

  • SendGrid
  • Mailgun
  • Postmark
  • Resend
  • Amazon SES (via API, not SMTP)

Your Worker makes a fetch() request to the provider’s API endpoint.

Example with a generic HTTP email API

export default {
  async fetch(request, env) {
    const res = await fetch("https://api.emailprovider.com/send", {
      method: "POST",
      headers: {
        "Authorization": `Bearer ${env.EMAIL_API_KEY}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        from: "you@example.com",
        to: "recipient@example.com",
        subject: "Hello from Cloudflare Workers",
        text: "This email was sent from a Worker.",
      }),
    });

    if (!res.ok) {
      return new Response(`Email send failed: ${await res.text()}`, { status: 500 });
    }

    return new Response("Email sent");
  }
};

Store the API key as a secret:

wrangler secret put EMAIL_API_KEY

2) Use Cloudflare Email Routing + Worker integration

If your goal is to receive and process inbound email, Cloudflare has built-in email handling via Email Routing and Workers.
That’s for incoming mail, not directly for sending outbound messages.


3) Use a backend service

If you already have an app server, your Worker can call your backend, and your backend handles SMTP or an email API.


Important limitations

  • Workers cannot open raw SMTP connections
  • Workers are best suited for HTTP-based email sending
  • Keep secrets in Worker secrets, not in code
  • If sending user-triggered email, add rate limiting / abuse protection

Recommended approach

If you want to send transactional emails from a Worker, use:

  • Resend or Postmark for simplicity, or
  • SendGrid/Mailgun if you already use them.

If you want, I can show you a complete Worker example using Resend, SendGrid, or Mailgun.

Observation history

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, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.