Engineering Notes · Nov 2026
What actually happens when you run a shared email domain for AI agents
Giving an AI agent an email address looks simple on paper. Spin up an SMTP relay, hook up an inbound webhook, hand the agent an API key, done. In practice, the plumbing takes an afternoon. Keeping the domain from getting blacklisted takes most of the real engineering.
Most builders hit the same three bad options first:
- Give the agent your personal Gmail. Now a prompt injection or a stray tool call has access to your password resets, billing, and identity.
- Buy a fresh domain per agent. Now you are managing DNS, SPF, DKIM, and cold-start warmup every time you spin up a new worker.
- Use a disposable burner service. Almost every service that matters (GitHub, Linear, Slack, Stripe) already blocklists burner domains, so OTPs never arrive.
A shared domain with managed reputation solves this for developers, because one API call gives an agent a working address with zero DNS setup. The catch is that the moment your shared domain has decent deliverability, spammers and burner-account farmers show up immediately.
The two abuse vectors that show up fast
Running theagentmail.net (MIT open-source email infrastructure on Cloudflare Workers) surfaced two distinct abuse patterns right away:
- Outbound phishing and unsolicited cold blasts. Someone creates a free trial account, names the org something generic, and immediately tries to blast cold outreach or phishing templates impersonating Meta or SaaS login alerts. If even a handful of those leave the server, spam complaints tank inbox placement for every legitimate agent on the domain.
- Free burner OTP farming. Automated scripts sign up for free trials just to receive signup and verification codes for other platforms, burning through addresses with zero intention of paying.
Four layers that actually stop it without breaking legit agents
Rate limits alone do not work, because ten phishing emails are enough to hurt domain reputation. Static keyword lists help for obvious templates, but spammers rephrase constantly. The setup that has held up in production layers four checks synchronously in the request path:
1. Phone verification on free trials
One-time SMS verification raises the floor so spinning up 50 throwaway orgs is not free. Phone numbers are canonicalized and checked atomically inside a Durable Object lock so concurrent requests cannot race trial creation.
2. Redacting inbound OTP and signup emails on free trials
Free trials still get full normal send, receive, and webhooks so builders can test their agent end-to-end. Inbound signup, OTP, and account-activation emails are redacted on free trials and unlock automatically as soon as an org adds a $5 prepaid deposit (which covers 5 mailbox-months at $1/mo and never expires). That single rule killed burner farming overnight without hurting real trials.
3. Synchronous AI outbound spam and phishing guard
Every outbound email passes through src/services/emailGuard.ts before it ever touches Resend. Both the plain-text and HTML bodies are inspected so hiding phishing text in one MIME part does not slip past. Legitimate 1:1 agent mail, deploy alerts, and human handoffs pass right through. Phishing, credential harvesting, and mass cold spam fail synchronously with 400 SPAM_REJECTED.
4. Durable Object locks, replay dedup, and strict webhook SSRF guards
Because outbound sends, quota accounting, and frozen-state checks run synchronously inside Cloudflare Durable Object locks, freezing a bad tenant takes effect immediately with zero queued backlog leaking out after a restart. Inbound webhooks verify Svix signatures with replay deduplication, and outbound customer webhooks use redirect: "manual" to block 3xx redirect SSRF chains.
The prompt-injection trap most agent email setups miss
Inbound email is untrusted text that gets fed straight into an LLM context window. Two things follow directly from that:
First, keys have to be scoped to one mailbox. Giving an agent an org-level admin key lets a prompt injection list neighboring mailboxes, mint keys, or inspect billing. An account-scoped key (am_...) only sees its own single inbox.
Second, watch out for persistent inbox forwarding. During security review for our Hermes Agent plugin, a reviewer pointed out a subtle attack: a prompt-injected email could instruct the agent to call create_webhook pointing at an attacker URL, silently exfiltrating every future email even after the session ends. Gating webhook creation behind an explicit human approval prompt showing the destination URL closes that hole cleanly:
def _require_webhook_approval(tool_name="", args=None, **kwargs):
if tool_name != "theagentmail_create_webhook":
return None
target = (args or {}).get("url", "<missing url>")
return {
"action": "approve",
"message": f"Register persistent AgentMail webhook to {target}?",
}Zero-friction integration for coding agents
The other thing we noticed watching people wire email into Claude Code, Hermes Agent, OpenClaw, and Cursor is that nobody wants to install a bloated wrapper SDK or maintain a local stdio bridge just to read an inbox.
We put a native Streamable HTTP remote MCP endpoint straight inside the Cloudflare Worker at https://api.theagentmail.net/mcp (published in the official MCP Registry as net.theagentmail/agentmail):
claude mcp add --transport http agentmail https://api.theagentmail.net/mcp \
--header "Authorization: Bearer am_..."If you prefer plain HTTP, pointing any coding agent at theagentmail.net/llms.txt gives it the entire REST and MCP spec in one fetch.
The entire stack (Cloudflare Workers, Durable Object guards, Resend, InstantDB, AI spam guard, remote MCP server, and Preact UI) is MIT open source. If you want to audit the code, fork the spam guard, or self-host it on your own domain, everything is in the repo.