Run agent email on your own Cloudflare account.
mails0 turns Cloudflare Workers, D1, R2, and Email Routing into a self-hosted email API for AI agents. Agents get durable inboxes, verification-code extraction, search, webhooks, and scoped keys without handing mailbox data to a SaaS vendor.
Why Cloudflare is a good base for agent email
Agent email is bursty, API-first, and global. Workers provide the request surface, Email Routing brings inbound messages into code, D1 stores searchable state, and R2 preserves raw mail and attachments.
Email arrives as code
Inbound messages can be parsed, labeled, stored, routed to webhooks, and exposed to agents without IMAP servers.
No private runtime
The core stack is standard Cloudflare infrastructure, so teams can audit and operate it themselves.
Tools above storage
mails0 adds the agent layer: CLI, Python SDK, MCP server, code extraction, search, scoped keys, and docs.
Reference architecture
| Layer | Cloudflare resource | mails0 responsibility |
|---|---|---|
| API | Workers | Authentication, inbox APIs, send APIs, code APIs, search APIs. |
| Inbound mail | Email Routing | Route email to Worker, persist raw message, parse headers and body. |
| Database | D1 | Store mailboxes, auth tokens, email metadata, FTS indexes, threads, labels. |
| Objects | R2 | Store raw MIME and attachments before parsing or webhook delivery. |
| Outbound | Resend in current release | Send mail through a verified sender domain and record delivery status. |
| Agent surface | CLI, MCP, SDK | Expose receive, send, search, code extraction, and thread operations. |
Deploy in minutes, then point agents at your Worker
Self-hosting keeps data in your account and lets you tune limits, domains, sender reputation, and retention policy.
git clone https://github.com/Digidai/mails.git
cd mails
wrangler d1 create mails-agent-db
wrangler r2 bucket create mails-agent-attachments
wrangler secret put RESEND_API_KEY
wrangler secret put AUTH_TOKEN
wrangler deploy
FAQ
Can I use Cloudflare's newer Email Service?
mails0's current production path uses Email Routing for inbound and Resend for outbound. Cloudflare's public Email Service direction is important for this market, and mails0's Workers architecture keeps that migration path practical.
Why not only use Cloudflare's reference apps?
Cloudflare provides platform primitives and examples. mails0 packages an agent-specific product layer: mailbox-scoped keys, CLI, Python SDK, MCP server, verification-code extraction, search, docs, and deployable source.