Development · Prompt
Cloudflare Email Service Migration Prompt
AI agent prompt for migrating transactional email to Cloudflare Email Service
A structured prompt designed for AI coding agents like Claude Code or Cursor to safely migrate an application's outbound email to Cloudflare Email Service. It guides the model through auditing existing send calls, writing an API wrapper, splitting domain reputation, and executing a staged rollout.
The prompt
Full prompt text as posted (kept verbatim by the saver; API URL had a space before .com in the tweet, to be removed):
---
I want to migrate this codebase's outbound email from its current provider (Postmark / SES / Resend / SendGrid / Mailgun / etc.) to Cloudflare Email Service (public beta, launched April 2026). Help me do this carefully.
Context: endpoint POST https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/email/sending/send, Authorization: Bearer {API_TOKEN}. Body: to (string or array), from (string or {address, name}), subject, html/text (one required), cc, bcc, reply_to, headers (e.g. List-Unsubscribe). Success: HTTP 200 + {"success":true,"result":{"delivered":[],"queued":[],"permanent_bounces":[]}}. Failure: non-200 OR success:false OR non-empty permanent_bounces — always check all three. Pricing: $5/mo Workers Paid plan + 3,000 emails free + $0.35 per 1k after (~5× cheaper than Postmark). No batch send endpoint — loop single sends.
Steps: (1) Verify prerequisites first — Workers Paid plan, sender domain onboarded in dashboard → Email → Email Sending → Onboard Domain (auto-adds SPF/DKIM/DMARC + cf-bounce MX), API token with email_sending:write scope, account ID. (2) Recommend splitting senders across subdomains: mail./members. → transactional, e. → cold/recovery, newsletter. → opt-in newsletters with List-Unsubscribe; each onboarded separately. (3) Grep-audit every email send in the codebase (provider SDKs, URLs, env vars, mail(), SMTP, nodemailer); group by email purpose, report before changing anything. (4) Add a single helper sendEmailViaCloudflare(): default from from config, parse "Name <email>" into {address,name}, accept cc/bcc string or array, accept headers dict, return bool, log failures where the codebase already logs (Telegram/Sentry/file), set 5s connect / 15s total fetch timeouts, treat non-empty permanent_bounces as soft failure. (5) Migrate one low-stakes email type first, test end-to-end. (6) Do NOT migrate magic-link login / password-reset emails yet — Cloudflare's reputation unproven; keep on current provider until ≥3 months clean deliverability. (7) Suggest focused git commits per migration.
Caveats to surface: beta, pricing not final, no SLA; no batch endpoint (~150ms/send ≈ 2.5min per 1000, fine for crons, bad for sync flows); no bounce webhooks (use permanent_bounces); suppression list auto-managed, spam-complaint suppressions hard to remove; no per-message logs (track via messageId); List-Unsubscribe headers passed verbatim — include them for Gmail bulk-sender compliance.
First action: ask for prerequisites and audit existing sends, then propose migration order with reasoning; wait for confirmation before coding.
What it's for
- Migrate transactional email from Postmark, Resend, or SendGrid to Cloudflare to cut costs
- Audit all outbound email call sites and SDK usage across a legacy codebase
- Implement a robust API wrapper for Cloudflare Email Service with bounce handling and timeouts
Key points
- Provides exact API endpoint schemas, authentication patterns, and failure condition logic
- Includes a step-by-step phased migration plan starting with an audit before making code edits
- Recommends subdomain reputation isolation strategies for transactional vs. marketing sends
- Outlines specific safety guardrails, such as keeping critical login emails on legacy providers
- Highlights technical constraints including the lack of batch endpoints and bounce webhooks
Pricing
Free
Details
- Type
- Prompt
- Category
- Development
- Topic
- AI Prompts
- Open source
- No
- Platforms
- Command line, other
- For
- Developers and technical founders using AI coding assistants to manage infrastructure migrations
- Tags
- claude code, cloudflare, transactional email, prompts, migration, email api
Why it was saved
- @levelsio: Encodes Cloudflare Email Service API details, pricing, and a cautious migration playbook (subdomain reputation split, audit, single helper, one email type at a time, keep login emails on the old provider) — reusable directly.
Related
Curated library of specialized AI agent personas and workflows for Claude Code
System prompt to convert rough software ideas into structured, agent-ready PRDs
A cheat sheet of 15 business and marketing prompts for ChatGPT.
Three-step transactional analysis prompt sequence for forecasting your future life trajectory
A collection of reusable ChatGPT prompts designed for studying and mastering topics
A system prompt that removes conversational fluff and engagement-seeking behaviors from LLMs
Updated