Architecture decision guide

Build vs buy agent email infrastructure by responsibility.

The decision is not open source versus SaaS in the abstract. It is a list of operational responsibilities your team either owns directly or assigns to a provider.

By Evidence checked 12 min read Editorial method

Direct answer

Buy a managed agent inbox or email provider when speed, vendor-operated reliability, support, and reduced infrastructure ownership matter more than source and deployment control. Self-host an open mailbox layer such as mails0 when domain ownership, data location, policy customization, auditability, or Cloudflare alignment justify operating Workers, D1, R2, routing, migrations, retention, limits, secrets, and incidents. Compose raw cloud email primitives only when the team needs a custom domain model and has platform capacity. A hybrid is often best: own agent mailbox semantics while using a managed provider for outbound delivery.

Visual guide

Four operating models for agent email

Ownership increases from managed product to composed infrastructure.

  1. 01
    Managed agent inbox

    Vendor operates identity, mailbox state, APIs, and infrastructure.

  2. 02
    Managed transport plus app

    Provider receives or sends; your application owns mailbox semantics.

  3. 03
    Open mailbox layer

    You deploy source and own data, policy, upgrades, and incidents.

  4. 04
    Cloud primitives

    You assemble transport, storage, parsing, state, tools, and operations.

Responsibility map

Split the stack before comparing products

Agent email contains at least four layers. Transport accepts and delivers messages. Mailbox state maps messages to identities, threads, search, and retention. Tooling exposes bounded operations to software actors. Workflow policy decides which content can cause which external action. Vendors stop at different layers.

A sending provider may own deliverability but not the agent's mailbox identity. An inbound parse webhook may deliver JSON but not retain a queryable conversation. An agent inbox SaaS may own both product and runtime. An open-source application may provide the behavior while leaving every production operation with your team.

Draw these layers and assign an owner before evaluating feature lists. Otherwise, the team can mistake source availability for low operating cost or mistake a parse webhook for a complete mailbox product.

LayerResponsibilitiesTypical owner choices
TransportDNS, SMTP receipt, sending, bounces, complaints, reputationManaged email provider or cloud service
Mailbox stateIdentity, storage, threads, search, labels, retentionAgent inbox product or application team
Agent toolsCLI, SDK, MCP, filters, extraction, result schemaProduct or platform team
Workflow authorityEligibility, approval, external actions, auditYour application and operators
Buy

Choose a managed product when operations are not a differentiator

A managed service can shorten the path to production by absorbing deployment, scaling, storage availability, product upgrades, and support. Managed sending platforms also operate infrastructure and reputation systems that are difficult to reproduce responsibly. For a small team, that transfer of work can be worth more than source access.

Buying does not transfer every responsibility. The customer still owns credential distribution, user authorization, prompt-injection defenses, content retention choices, action policy, application observability, and incident coordination. Review current contracts, data handling, export paths, quotas, support, and shutdown behavior rather than assuming SaaS removes risk.

  • Buy when launch speed and vendor operation outweigh custom policy.
  • Verify the exact mailbox, event, attachment, and sending capabilities needed.
  • Keep provider credentials scoped and outside model context.
  • Design export and replacement paths before the data becomes critical.
Self-host

Choose open source when control is a requirement the team will operate

Self-hosted mails0 runs the application in the operator's Cloudflare account using Workers, D1, R2, and Email Routing. The team can inspect and modify identity, storage, limits, extraction, webhook, and lifecycle behavior. It can use its own domain and decide how policy fits existing platform systems.

That control creates a release and incident surface. The team must manage Cloudflare resources, DNS, migrations, secrets, R2 objects, retention jobs, rate limits, abuse controls, outbound provider configuration, logs, alerts, rollback, and security updates. Free infrastructure allowance does not make engineering and operational work free.

Self-host when those controls are material to product, compliance, data, or architecture and the team can name the owner. Do not self-host only because the repository is available.

  1. 01

    Validate in the hosted sandbox

    Prove the API and workflow before taking on infrastructure.

  2. 02

    Inventory production requirements

    List domain, retention, volume, attachments, events, sending, and policy.

  3. 03

    Deploy with release evidence

    Apply migrations, bindings, secrets, routing, and smoke tests in order.

  4. 04

    Operate the stop path

    Test pause, credential rotation, rollback, cleanup, and incident ownership.

Compose primitives

Build from cloud components only when mailbox semantics are product-specific

Cloudflare Email Routing, Cloudflare Email Sending, Amazon SES receipt rules, provider parse webhooks, object storage, databases, queues, and functions can be assembled into a custom system. This is appropriate when the product has unusual tenant, routing, compliance, message-state, or integration requirements that an inbox product cannot represent.

The hidden work includes MIME parsing, attachment safety, thread reconstruction, search, idempotency, tenant authorization, credential recovery, retention, event retries, tooling, dashboards, and migrations. Estimate these as product features and ongoing operations, not a one-time webhook handler.

Good reason

Unique domain model

Mailbox and message behavior directly differentiate the product.

Weak reason

Avoiding a modest vendor bill

Engineering time, incident risk, and maintenance can dominate transport cost.

Requirement

Platform capacity

A team owns runtime, security, data, testing, and long-term upgrades.

Hybrid

Own the application layer and buy delivery when that boundary is stable

A common architecture self-hosts mailbox identity and state while delegating outbound delivery to a provider. This keeps source, data, domain behavior, and agent tools under application control without attempting to reproduce sender reputation and global delivery operations.

Keep the provider adapter explicit. Record send request, provider acceptance, delivery events, inbox placement when observable, and recipient action separately. For inbound, document whether Cloudflare routing, a provider parse webhook, or another service is authoritative. A hybrid reduces some work but still needs an integrated incident model.

Decision signalManagedSelf-hosted or hybrid
Need production quicklyStrong fitStart with sandbox, add later
Need source and custom policyCheck vendor limitsStrong fit with owner
Need managed deliverabilityStrong fitUse provider for outbound
Limited platform capacityStrong fitOperational risk
Cloudflare-aligned runtimePossible integrationmails0 path is direct
Implementation judgment

Choose from measured requirements, then revisit the boundary

Run a real workflow before committing to infrastructure. After the first successful and repeated use, write down volume, latency, data, identity, sending, support, compliance, and incident requirements. Select the highest product layer you want a provider to own, and keep the interfaces between transport, mailbox, tools, and policy explicit enough to change later.

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

Questions that come up in practice

Is self-hosting agent email cheaper?

Infrastructure may be inexpensive at low volume, but total cost includes engineering, migration, monitoring, security, abuse response, support, and incidents. Compare total ownership, not only provider price.

Can I self-host mailboxes and use a managed sender?

Yes. That hybrid separates mailbox identity and state from outbound delivery. The current mails0 implementation supports a configured outbound provider such as Resend.

When should I build from Amazon SES or Cloudflare primitives?

Build from primitives when the mailbox domain model is product-specific and a platform team is prepared to own parsing, state, tools, policy, migrations, and operations.

Start with a bounded inbox

Prove the smallest useful email loop.

Start with one scoped inbox and one expected message. Add durable identity, sending, and operational complexity only when the first loop works.