agentleFS
danmestasdanmestas/wardrobe/skills/cloudflare-email/SKILL.md

cloudflare-email

Skill4 starsChanged 7 months agoMITView on GitHub

Use when sending outbound transactional or one-off emails from a Cloudflare-managed domain without running a mail server or paying for a mailbox provider. Triggers on needs to send email programmatically from a custom domain, send-from-my-domain requests, or replacing SMTP relays. Cloudflare Email Service is REST API + Workers only — no SMTP, so it is NOT compatible with Gmail "Send mail as", Outlook, or any SMTP client.

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 4 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Do NOT use when:

    line 29
  2. Distinctive:

    When sending from a Worker, use the binding instead of the REST API — lower latency, no token management:

    line 92
  3. Very specific:

    Add a routing rule: you@yourdomain.com → forward to a real inbox (Gmail, iCloud, etc.)

    line 137
  4. Distinctive:

    Do not rely on Cloudflare to store or resurface outbound content.

    line 160
  5. Distinctive:

    Per-account rate limits apply: Check current limits in Cloudflare docs — exceed them and sends queue or reject.

    line 165
  6. Very specific:

    Bounces go to cf-bounce.<domain>: Don't delete those DNS records.

    line 166

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Cloudflare Email Service (Sending)

Send outbound email from a Cloudflare-hosted domain via REST API or Workers binding. Complements Cloudflare Email Routing (inbound-only) to give a domain full send/receive with no mailbox provider.

When to Use vs Not Use

Use when:

  • Sending programmatically (alerts, transactional mail, one-off scripts)
  • Domain is already on Cloudflare DNS
  • You don't need a human-facing inbox / "Sent" folder

Do NOT use when:

  • User wants to send from Gmail, Apple Mail, Thunderbird, or any SMTP client (Cloudflare exposes no SMTP endpoint — use Zoho/Workspace/Fastmail instead)
  • User needs IMAP, a Sent folder, or threaded reply UI
  • Sending from a domain not on Cloudflare DNS

Prerequisites

  1. Domain on Cloudflare DNS — zone active, nameservers delegated.
  2. Email Service enabled — Dashboard → your domain → Email → Email Service → enable. This auto-adds MX/SPF/DKIM/DMARC records on a cf-bounce.<yourdomain> subdomain for bounce handling and authentication. Do not delete those records.
  3. Account ID — dashboard sidebar, or wrangler whoami.
  4. API Token — https://dash.cloudflare.com/profile/api-tokens → Create Token → custom token with Email Sending: Edit permission scoped to your account. Save as CF_API_TOKEN.
  5. Verified sender — the from address must be on a domain where Email Service is enabled. Cloudflare rejects sends from unverified domains.
export CF_ACCOUNT_ID="your-account-id"
export CF_API_TOKEN="your-api-token"

Send via REST API

curl -sS "https://api.cloudflare.com/client/v4/accounts/$CF_ACCOUNT_ID/email/sending/send" \
  -H "Authorization: Bearer $CF_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "from":    "you@yourdomain.com",
    "to":      "recipient@example.com",
    "subject": "Subject line",
    "text":    "Plain text body.",
    "html":    "<p>HTML body.</p>"
  }'

A 200 with "success": true means queued for delivery. A 400 usually means the sender domain isn't verified or Email Service isn't enabled on it.

Payload Fields

FieldRequiredNotes
fromyesMust be on a domain with Email Service enabled
toyesSingle recipient or array
subjectyes
textone of text/html requiredPlain-text body
htmlone of text/html requiredHTML body
cc, bccnoArrays of addresses
reply_tonoWhere replies go if different from from

Send from a Markdown File

Common one-off: turn a hand-written markdown draft into a sent email. See scripts/send-email.sh in this skill for a working helper. Usage:

./send-email.sh \
  --from you@yourdomain.com \
  --to   recipient@example.com \
  --subject "Subject line" \
  --body draft.md

It strips markdown for the text field, renders minimal HTML for the html field, and POSTs to the API.

Send via Workers Binding

When sending from a Worker, use the binding instead of the REST API — lower latency, no token management:

# wrangler.toml
send_email = [
  { name = "SEND_EMAIL" }
]
import { EmailMessage } from "cloudflare:email";
import { createMimeMessage } from "mimetext";

export default {
  async fetch(req, env) {
    const msg = createMimeMessage();
    msg.setSender({ name: "App", addr: "you@yourdomain.com" });
    msg.setRecipient("recipient@example.com");
    msg.setSubject("Hello");
    msg.addMessage({ contentType: "text/plain", data: "Body" });

    await env.SEND_EMAIL.send(new EmailMessage(
      "you@yourdomain.com",
      "recipient@example.com",
      msg.asRaw()
    ));
    return new Response("sent");
  }
}

Common Errors

ErrorCauseFix
Sender domain not verifiedEmail Service not enabled on from domainDashboard → Email → enable Email Service
Authentication errorToken missing Email Sending: EditRecreate token with correct permission
Invalid recipientTypo or unroutable domainVerify the to address
Missing required parameterNo text and no htmlInclude at least one body field
DNS records missing in dashboardRecords manually deletedRe-enable Email Service to restore

Receiving Replies

Cloudflare Email Service handles outbound only. To receive replies:

  • Enable Email Routing on the same domain (separate product, same dashboard)
  • Add a routing rule: you@yourdomain.com → forward to a real inbox (Gmail, iCloud, etc.)
  • Replies then land in that inbox; you reply from that inbox's UI (which may itself need a Send-as alias to preserve the custom-domain from)

Viewing Sent Mail

Dashboard → your domain → Email Service → Email Sending → Activity Log lists recent sends, destinations, and delivery status. Logs can take up to ~2 minutes to appear.

Only mail sent through Cloudflare (REST API or Workers binding) shows up. Mail that happens to use a from address on a Cloudflare-verified domain but is relayed by another service (e.g. Gmail's smtp.gmail.com delivering a "Send mail as" alias) bypasses Cloudflare entirely and will NOT appear in the Activity Log — this is a common point of confusion when debugging whether a send actually went through this service.

Session detail view exposes the RFC 5322 Message-ID (e.g. <NpkoCxVOvUVmswnF9h9vvVjiZoW9lgivY4xH@yourdomain.com>). Useful for:

  • Matching bounces (bounce reports reference the Message-ID)
  • Threading with the recipient's reply in their mail client
  • Correlating with external logs if you shipped the payload to your own logger

The Message-ID is not returned in the POST /email/sending/send HTTP response — you only see it in the dashboard session view or embedded in the delivered email's headers.

No API to Retrieve Sent Content

Cloudflare exposes no endpoint to list past sends, fetch a message by ID, or retrieve a previously-sent body. The send endpoint's 200 response body does not include a message_id either. If you need an audit trail of what was actually delivered:

  • Log the JSON payload yourself before calling the API (disk, database, logging service)
  • Or save a copy to an inbox you control via bcc

Do not rely on Cloudflare to store or resurface outbound content.

Limitations

  • No SMTP. This is the single biggest footgun — users frequently ask to point Gmail Send-as at Cloudflare. It does not work and cannot work. Redirect them to a real mailbox provider if they need SMTP.
  • Per-account rate limits apply. Check current limits in Cloudflare docs — exceed them and sends queue or reject.
  • Bounces go to cf-bounce.<domain>. Don't delete those DNS records.

References

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.