Cloudflare Email Service API: How to Send Email from Workers (REST, Binding, SMTP)

Set up Cloudflare Email Service, then send email from a Worker binding, the REST API or SMTP, track delivery events and test the send endpoint with your coding agent.

INEZA Felin-Michel

INEZA Felin-Michel

26 November 2026

Cloudflare Email Service API: How to Send Email from Workers (REST, Binding, SMTP)

Apidog for Enterprise

On-Premises Deploy

SSO & RBAC

SOC 2 Compliant

Explore Apidog Enterprise

The Cloudflare Email Service API lets you send transactional email three ways: a Workers binding (env.EMAIL.send()), a REST endpoint (POST /accounts/{account_id}/email/sending/send) and authenticated SMTP on smtp.mx.cloudflare.net:465. Onboard a sending domain first. On Workers Free you can send only to verified destination addresses; Workers Paid sends to anyone, with 3,000 emails a month included.

Cloudflare opened Email Sending to Workers Free on November 24, 2026. This guide covers the full setup: domain, recipients, all three interfaces, delivery events and an agent-run test.

What is the Cloudflare Email Service API?

The Cloudflare Email Service API is the sending half of Cloudflare Email Service. It accepts a message from a Worker binding, an HTTP request or an SMTP session, signs it with DKIM, delivers it from your onboarded domain and records the result in the Activity log. All three interfaces share one pipeline and one set of limits.

Pick the interface by where your code runs:

Interface Use it when Auth Success signal
Workers binding Your code runs on Cloudflare Workers The binding itself, no token send() resolves with messageId
REST API Any backend, serverless function or CI job API token in Authorization: Bearer success: true, result.message_id
SMTP An app or library that already speaks SMTP Username api_token, password = API token 250 after DATA

You must use Cloudflare DNS for the sending domain. If you’re new to Cloudflare’s API tokens and account IDs, the Cloudflare APIs guide covers the basics.

Before you send: onboard a domain and verify recipients

You need two things in place before the first message goes out: an onboarded sending domain and, on Workers Free, at least one verified destination address.

  1. In the Cloudflare dashboard, open Compute > Email Service > Email Sending and select Onboard Domain.
  2. Pick a domain from your account. Cloudflare adds MX, SPF and DKIM records on the cf-bounce subdomain, plus a DMARC record on _dmarc.yourdomain.com.
  3. Wait for DNS. Cloudflare says propagation usually takes 5 to 15 minutes on its own DNS, up to 24 hours worst case.
  4. Open Email Routing > Destination Addresses, enter the address that will receive your test mail and click the link in the verification email.
  5. Create an API token with the Email Sending: Edit permission if you’ll use REST or SMTP.

Destination addresses are shared across every domain in the account, with a cap of 200. Sends to them are free on every plan and don’t count toward the monthly quota or the daily limit, per the destination addresses docs.

Workers binding, REST API and SMTP pass the plan check and daily limit, then deliver from the onboarded domain

Send email from a Worker with the binding

The binding is the shortest path when your code already runs on Workers. Add a send_email entry to your Wrangler config:

{
  "send_email": [
    { "name": "EMAIL", "remote": true }
  ]
}

remote: true makes npx wrangler dev send through the real service while your code runs locally. Then call send() from your handler:

export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    try {
      const { messageId } = await env.EMAIL.send({
        to: "you@yourcompany.com", // a verified destination address on Free
        from: "alerts@yourdomain.com",
        subject: "Disk usage above 90%",
        text: "Disk usage on db-1 is above 90%.",
        html: "<p>Disk usage on <b>db-1</b> is above 90%.</p>",
      });
      return Response.json({ sent: true, messageId });
    } catch (err: any) {
      if (err.code === "E_RECIPIENT_PLAN_RESTRICTED") {
        return new Response("Recipient is not verified on Workers Free", { status: 403 });
      }
      if (err.code === "E_DAILY_LIMIT_EXCEEDED" || err.code === "E_RATE_LIMIT_EXCEEDED") {
        return new Response("Sending limit reached, try later", { status: 429 });
      }
      throw err;
    }
  },
} satisfies ExportedHandler<Env>;

Deploy with npm run deploy and hit the Worker URL. A string messageId means Cloudflare accepted the message.

The binding throws errors with a string code. Besides the two above, expect E_SENDER_DOMAIN_NOT_AVAILABLE (the from domain isn’t onboarded), E_EMAIL_SENDING_NOT_READY (onboarding hasn’t finished) and E_VALIDATION_ERROR (bad address or no body). The Workers API reference lists the rest.

To lock a binding down, add allowed_sender_addresses or allowed_destination_addresses to its config. Sends outside those lists fail with E_SENDER_NOT_VERIFIED or E_RECIPIENT_NOT_ALLOWED.

Send email with the Cloudflare Email REST API

Use REST when your sender lives outside Workers: a Node or Python backend, a cron job or a CI step. It’s one request:

curl "https://api.cloudflare.com/client/v4/accounts/$CF_ACCOUNT_ID/email/sending/send" \
  --header "Authorization: Bearer $CF_API_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
    "to": "you@yourcompany.com",
    "from": "welcome@yourdomain.com",
    "subject": "Welcome aboard",
    "html": "<h1>Welcome!</h1><p>Thanks for signing up.</p>",
    "text": "Welcome! Thanks for signing up."
  }'

A success groups recipients by outcome:

{
  "success": true,
  "errors": [],
  "messages": [],
  "result": {
    "message_id": "<aB3xK9mP2qR5sT8uV0wX1yZ4cD6fG7hJ9kL0@example.com>",
    "delivered": ["you@yourcompany.com"],
    "permanent_bounces": [],
    "queued": [],
    "suppressed_recipients": []
  }
}

Check the arrays, not just success. A recipient in permanent_bounces or queued hasn’t landed, even though the call returned 200.

Failures use numeric codes in errors[]. The ones worth handling explicitly, from the REST API reference:

HTTP Code Meaning What to do
400 10001 Invalid request schema Fix the payload; don’t retry
403 10102 Token lacks send permission Add Email Sending: Edit
403 10208 Plan allows only verified destinations Verify the address or move to Workers Paid
429 10004 Rate limit exceeded Back off and retry

Send email over Cloudflare SMTP

SMTP is for software you don’t want to rewrite, like an existing Nodemailer or smtplib setup. It accepts implicit TLS on port 465 only; STARTTLS on 587 isn’t supported.

Setting Value
Host smtp.mx.cloudflare.net
Port 465 (implicit TLS)
Auth PLAIN or LOGIN
Username the literal string api_token
Password your Cloudflare API token

In Nodemailer that becomes:

import nodemailer from "nodemailer";

const transport = nodemailer.createTransport({
  host: "smtp.mx.cloudflare.net",
  port: 465,
  secure: true,
  auth: { user: "api_token", pass: process.env.CF_API_TOKEN },
});

await transport.sendMail({
  from: "reports@yourdomain.com",
  to: "you@yourcompany.com",
  subject: "Nightly report",
  text: "All 42 jobs passed.",
});

Watch three response codes: 451 4.7.1 means you hit the rate or daily limit (retry later), 535 5.7.8 means authentication failed, and 550 5.7.1 means the sender or recipient was denied. The SMTP reference lists the rest.

Track delivery with Email Sending events

A messageId means Cloudflare accepted the message, not that it arrived. For that, subscribe to Email Sending events: each subscription covers one sending domain and publishes to a Cloudflare Queue that a Worker consumes.

Six event types are available: message.delivered, message.deferred, message.bounced, message.failed, message.rejected and message.complained. Each payload carries messageId, recipient and a delivery block with the SMTP status code. Verified-recipient sends now go through Email Sending too, so they appear in the Activity log and analytics.

A consumer that records bounces looks like this:

export default {
  async queue(batch: MessageBatch<any>, env: Env) {
    for (const msg of batch.messages) {
      const event = msg.body;
      if (event.type === "cf.email.sending.message.bounced") {
        await env.BOUNCES.put(event.payload.recipient, event.payload.messageId);
      }
      msg.ack();
    }
  },
};
A Worker sends, gets messageId, and a Queue receives message.delivered or message.bounced

Limits and pricing you’ll hit first

The numbers below come from Cloudflare’s pricing and limits pages, read on November 26, 2026.

Workers Free Workers Paid
Recipients Verified destination addresses only Anyone
Included sends Free to verified addresses 3,000 per month
Overage Not applicable $0.35 per 1,000 emails
Verified-address sends Free, outside quota and daily limit Free, outside quota and daily limit

Every plan shares the per-message limits: 50 recipients across to, cc and bcc, a 998-character subject, 25 MiB total size and 16 KB of custom headers. New accounts also start with a conservative daily limit that grows with sending reputation. Cloudflare doesn’t publish the starting number. Over it, the binding throws E_DAILY_LIMIT_EXCEEDED, REST returns HTTP 429 and SMTP answers 451 4.7.1.

So Free suits team alerts and development; customer mail like signups and receipts needs Workers Paid. If you’re still comparing providers, the email API integration roundup and the free email APIs guide cover other options.

Let your coding agent test the send endpoint with Apidog CLI

Once the REST call works by hand, you want it checked on every change. Let your coding agent do that with Apidog CLI: it keeps the Cloudflare base URL in an environment and runs a test scenario against the live endpoint.

Install the CLI and the agent skill once:

npm install -g apidog-cli@latest
apidog login --with-token <YOUR_TOKEN>
npx -y skills add https://apidog.com   # pick your agent when prompted

Then give Claude Code, Codex or your agent of choice one prompt:

In Apidog project <id>, create an environment "cloudflare-email" with base URL
https://api.cloudflare.com/client/v4. Add a test scenario that calls
POST /accounts/{{CF_ACCOUNT_ID}}/email/sending/send to {{VERIFIED_TO}} and asserts
HTTP 200, success is true and result.message_id exists. List the environments and
scenarios, then run the scenario with my account ID and token passed as env vars.

The agent reads the payload schema before it writes anything, then runs these commands:

apidog environment list --project <id>
apidog environment create cloudflare-email --project <id> --base-url https://api.cloudflare.com/client/v4
apidog cli-schema get test-scenario-create
apidog test-scenario create --project <id> --file send-scenario.json
apidog test-scenario list --project <id>
apidog run --project <id> -t <scenarioId> -e <environmentId> \
  --env-var CF_ACCOUNT_ID=<accountId> --env-var CF_API_TOKEN=<token> \
  --env-var VERIFIED_TO=you@yourcompany.com -r cli,junit
Apidog CLI listing environments and test scenarios in a sandbox project

--env-var keeps the token out of the saved environment, and -r cli,junit gives CI a report. With a verified recipient, the run is free and skips the daily limit, so it’s safe on every commit. The Apidog CLI in Claude Code guide and the apidog run reference cover more flags.

A coding agent runs an Apidog CLI test scenario against the Cloudflare send endpoint

When those agent runs become a weekly habit, Sharkly lets your team hand them out as tasks on a board: each coding agent, Claude Code or Codex included, runs on your own computer with your own plan, and you review what it ships before it merges. It’s free to start.

Wrapping up

The Cloudflare Email Service API is one pipeline with three doors: the binding inside Workers, REST everywhere else and SMTP for legacy code. Build on Workers Free against verified addresses, move to Paid for customer mail and subscribe to events to see what landed.

FAQ

Is the Cloudflare Email Service API free?

On Workers Free, yes, but only to verified destination addresses. Workers Paid includes 3,000 emails a month to anyone, then $0.35 per 1,000.

What does E_RECIPIENT_PLAN_RESTRICTED mean?

Your account is on Workers Free and the recipient isn’t a verified destination address. Verify the address under Email Routing > Destination Addresses, or upgrade to Workers Paid. Over REST the same failure is HTTP 403 with code 10208.

Can I send Cloudflare email without Workers?

Yes. REST and SMTP work from any backend with an API token. The sending domain still needs Cloudflare DNS and onboarding.

Does Cloudflare SMTP support port 587?

No. Submission runs on smtp.mx.cloudflare.net port 465 with implicit TLS. STARTTLS on 587 and unauthenticated relay on 25 aren’t supported for outbound mail.

How do I know if a Cloudflare email was delivered?

The send call only confirms acceptance. Read message.delivered and message.bounced events from a Queue, or check the Activity log.

Explore more

1Password Breach: What It Teaches About API Tokens

1Password Breach: What It Teaches About API Tokens

What did the 1Password breach expose? Learn what stayed safe and how to test your own API for recovery token expiry, single use and rate limits.

26 November 2026

Claude Install as App: How to Turn Artifacts into Mac and Windows Apps

Claude Install as App: How to Turn Artifacts into Mac and Windows Apps

Want to use Claude install as app? Learn how to turn any Claude artifact into a Mac or Windows app and pick the right permissions for it.

25 November 2026

Claude approvals.yml: Require API Tests Before Merge

Claude approvals.yml: Require API Tests Before Merge

Want to pair Claude approvals.yml with API tests? Learn how to use Apidog and GitHub to block merges until the required checks pass.

24 November 2026

Practice API Design-first in Apidog

Discover an easier way to build and use APIs

Cloudflare Email Service API: How to Send Email from Workers (REST, Binding, SMTP)