Cloudflare email for agents

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.

Programmable

Email arrives as code

Inbound messages can be parsed, labeled, stored, routed to webhooks, and exposed to agents without IMAP servers.

Portable

No private runtime

The core stack is standard Cloudflare infrastructure, so teams can audit and operate it themselves.

Agent-ready

Tools above storage

mails0 adds the agent layer: CLI, Python SDK, MCP server, code extraction, search, scoped keys, and docs.

Reference architecture

LayerCloudflare resourcemails0 responsibility
APIWorkersAuthentication, inbox APIs, send APIs, code APIs, search APIs.
Inbound mailEmail RoutingRoute email to Worker, persist raw message, parse headers and body.
DatabaseD1Store mailboxes, auth tokens, email metadata, FTS indexes, threads, labels.
ObjectsR2Store raw MIME and attachments before parsing or webhook delivery.
OutboundResend in current releaseSend mail through a verified sender domain and record delivery status.
Agent surfaceCLI, MCP, SDKExpose 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.