The self-hosted data plane for Cloudflare Mail — an ingest Worker + D1 that receives your domain's mail, stores it, and sends replies, all in your own Cloudflare account. The adaptive inbox app (hosted) reads it over a tokened HTTP API. Your mail never leaves your account.
This provisions a D1 database + the ingest Worker and gives you a Worker
URL like https://cf-mail-ingest.<you>.workers.dev. The Worker creates its own
tables on first request — no migration step.
Generate a strong random token, set it as a secret, and keep a copy — you'll paste it into Connect:
openssl rand -hex 32 # copy this
npx wrangler secret put MAIL_API_TOKEN # paste itOptional, to let the inbox admin panel auto-create per-user routing rules:
# Token scopes: Zone → Zone (Read) + Zone → Email Routing Rules (Edit)
npx wrangler secret put CF_API_TOKEN- Email Routing (receiving): enable it, then route each address to this
Worker (
npx wrangler email routing enable yourdomain.com). The inbox admin panel creates per-address rules for you onceCF_API_TOKENis set. - Email Sending (replies): onboard your domain (Cloudflare dashboard →
Email Service → Email Sending, or
wrangler email sending enable yourdomain.com).
Go to the hosted app's “Set up your Cloudflare domain” page and enter:
- your domain,
- the Worker URL from step 1,
- the
MAIL_API_TOKENfrom step 2, - your admin username.
You'll get a one-time setup link to activate your admin inbox. Done.
src/index.ts — email() ingest handler + a tokened HTTP API (threads, send,
auth, admin, control). src/schema.ts — self-migrating D1 schema. This is a
snapshot of the worker/ directory in the main app repo.