Direct answer

Can I self-host email for AI agents?

Yes, if your team is prepared to own domain, data, sender configuration, migrations, monitoring, abuse controls, and incidents.

Maintained by Evidence checked Editorial method

Open the quickstart
Direct answer

Yes. mails0 is MIT licensed and documents a self-hosted architecture on Cloudflare Workers, D1, R2, and Email Routing. You provide the Cloudflare account, domain, secrets, database and bucket, outbound sender provider, quotas, retention, monitoring, and operational response. Self-hosting gives control but does not eliminate email operations.

Visual guide

Decision map

The documented Cloudflare architecture

  1. 01
    API and inbound processing

    Serve authenticated mailbox routes and process Email Routing events.

  2. 02
    Queryable metadata

    Store identities, token state, message indexes, labels, threads, and quotas.

  3. 03
    Raw message storage

    Preserve MIME and attachments under explicit retention and access policy.

Stack

The documented Cloudflare architecture

Workers

API and inbound processing

Serve authenticated mailbox routes and process Email Routing events.

D1

Queryable metadata

Store identities, token state, message indexes, labels, threads, and quotas.

R2

Raw message storage

Preserve MIME and attachments under explicit retention and access policy.

Deployment

Build the service in verifiable stages

  1. 01

    Create and migrate resources

    Provision D1 and R2 and apply the current schema with compatibility checks.

  2. 02

    Deploy and configure secrets

    Store secrets in Cloudflare and verify the Worker health endpoint.

  3. 03

    Route inbound mail

    Use a dedicated subdomain and send an external message through Email Routing.

  4. 04

    Configure outbound separately

    Verify the sender provider and track acceptance and delivery states independently.

  5. 05

    Harden operations

    Set limits, retention, cleanup, monitoring, backups, and incident controls.

Tradeoff

Control and responsibility arrive together

Self-hosting is valuable when your domain, data location, source review, quotas, or integration behavior are requirements. It is not automatically simpler or cheaper than a managed provider.

Your team must own DNS, sender reputation, migrations, secret rotation, Cloudflare limits, monitoring, backups, abuse response, and updates. Choose a managed service when reducing those operations is the higher priority.

  • Use a subdomain to protect existing human mail.
  • Keep operator and mailbox credentials separate.
  • Test external inbound and outbound paths.
  • Document retention and deletion before production data arrives.
Decision

Hosted sandbox or self-hosted

RequirementUse hosted sandboxSelf-host when
First proofYou need one temporary receive-only mailbox.You already know the production requirements.
DomainHosted domain is acceptable.The agent must use your domain.
DataHosted service boundary is acceptable.Mailbox data must stay in your account.
SendingHosted capability and limits fit.You need your own sender and policy.
OperationsYou want minimal setup.Your team can own the full lifecycle.
Implementation judgment

Self-host only when ownership is part of the requirement

The architecture is practical, but production readiness includes more than deployment. Assign ongoing responsibility for DNS, provider configuration, migrations, retention, monitoring, backups, abuse controls, key rotation, and incident response before moving durable agent identities onto the service.

Evidence

Sources and product scope

Product behavior is verified against the mails0 source and documentation. External comparisons link to official vendor documentation checked on 2026-08-15.

Questions and answers

Related questions

Is the self-hosted code free?

mails0 is MIT licensed. Cloud, provider, domain, and engineering costs remain separate.

Can Cloudflare Email Routing send email?

No. It routes inbound email. Configure a verified outbound sender provider for sending.

Can I use my root domain?

You can, but a dedicated subdomain is usually safer when the root domain already handles human email.

Start with a bounded inbox

Give the agent an inbox, then prove the workflow.

Start with a receive-only temporary mailbox. Move to a permanent identity or self-hosted deployment only after the workflow reaches a real email value event.

Open the quickstart