Skip to content
Tinbox

tutorials

Self-hosted webmail: a Gmail-style inbox you host on your own domain

November 4, 2026

#self-hosted-webmail#inbox#cloudflare#d1#gmail-alternative
Conceptual textless workspace panels show a queue, reading pane, and context.

An inbox on your own domain, reading data you own, is the part most people don't expect a self-hosted stack to include.

When developers say "self-hosted email," they usually mean the plumbing: MX records, a mail server, maybe an API to send. The part that gets quietly dropped is the inbox itself, the human-facing UI where someone actually reads a support thread, searches for last month's receipt, and hits reply. That UI is the hard, unglamorous part, so most self-hosted email projects ship an API and tell you to bring your own client (Thunderbird, Apple Mail, a webmail package you bolt on separately).

This tutorial is about the other path: a webmail inbox that ships with the stack, runs on your own domain, and reads the same database your transactional sender and newsletter tool already write to. We will cover what the UI actually is, where the mail comes from, how search and reply work, and where Gmail still beats you. Be warned up front: this is honest about the gaps.

Yes, there is a real inbox UI

Tinbox ships a real threaded webmail client, not just an API. It is a single-page app served by the same Cloudflare Worker that holds your data, so the inbox lives at a hostname on your own domain (for example https://mail.yourdomain.com) inside your own Cloudflare account. You open it in a browser, you see folders and threads, you click a conversation and read it, you reply.

The distinction matters because most "self-hosted email" tools stop at the data layer. They give you an inbound handler and a sending endpoint and leave the reading experience to you. That is fine for a notification pipeline, but it is not a Gmail replacement. A person on your team will not read support mail through curl. The webmail client is what turns owned data into something a human uses every day.

Concretely, the inbox gives you:

  • A threaded view: messages grouped into conversations by subject and references, the way you expect mail to read.
  • Reading with the original formatting, inline images served from R2, and attachments.
  • Search across all your mail (more on the FTS5 engine below).
  • Compose and reply, sending through your own HTTPS sender on the same account.

It is the same UI the AI agent and email interpreters plug into, which is what makes the inbox more than a folder. We will get to that.

Where does the mail come from?

Mail lands in the inbox through Cloudflare Email Routing, which hands each inbound message to a Worker that parses it and writes it to D1 and R2. The inbox UI then reads those rows. This is the load-bearing fact to understand before you set anything up: the webmail client is a reader over a database, and the database is filled by the inbound pipeline. No inbound pipeline, no mail, empty inbox.

The flow is:

  1. Cloudflare Email Routing accepts mail at your domain (it provisions the MX records).
  2. A routing rule sends each message to your Worker's email() handler.
  3. The handler parses the MIME, writes structured fields (from, to, subject, date, body, headers) into D1, and puts the raw .eml plus attachments into R2.
  4. The webmail UI queries D1 to render threads and serves bodies and attachments from R2.

The full inbound plumbing, enabling routing, exporting the handler, parsing, dedup on Message-ID, is its own walkthrough: see how inbound mail lands in the inbox. The important point here is that the inbox sits on top of that pipeline as the human UI.

For existing mail, you do not start from an empty inbox unless you want to. The local-fetch importer CLI pulls your history from Gmail, IMAP, or an mbox export and bulk-inserts it into the same D1 tables, so the inbox shows years of history from day one. The mechanics (OAuth, fetching locally, why the bulk insert runs Worker-side) are covered in import your Gmail into this inbox. The split is deliberate: that article is how the mail gets in; this one is what you do with it once it is there.

What is the inbox experience like?

You read threads, search, and reply, with the work happening on data you own. Open the inbox at your domain and you get a conversation list. Click a thread and the messages stack in order with quoted history collapsed. It behaves like webmail because it is webmail; the difference is whose servers it runs on.

Search that is actually a query

Search runs on SQLite FTS5, a full-text index built into D1, so a query like invoice from:acme returns ranked matches without leaving your Cloudflare account. FTS5 indexes the message bodies, subjects, and participants. When you search, the UI runs a query against that index in your own database and renders the hits. There is no third-party search service, no data shipped off to an external index, and no per-query cost beyond the D1 reads you already pay for.

This is a genuine difference from "self-hosted" setups that quietly send your mail to a hosted search provider to make search usable. Here the index is a table in the same SQLite database as the mail. If you want the internals (how the FTS5 virtual table is built and queried, tokenization, ranking), read the FTS5 search behind the inbox.

Compose and reply send through your own sender

When you reply, the message goes out through your own HTTPS-based sender on the same Cloudflare account, and the sent copy threads back into the conversation. This is where the inbound/outbound split shows up in the UI. Cloudflare Workers cannot open outbound port 25 for direct-to-MX SMTP, so sending is never "the inbox talks SMTP." Instead, reply hands the composed message to the transactional sender, which delivers it over HTTPS and records the sent message back into D1 so it appears in the thread. The reader and the sender are two halves of the same stack, sharing one database.

What is the payoff of one shared dataset?

Because the inbox reads the same D1 data as your sender and newsletter, one contact has one record across transactional mail, marketing campaigns, and support threads. This is the unification argument, and it is the reason to run the inbox next to the sender rather than as a separate product.

Picture a customer, dana@example.com. In a typical stack, her receipt lives in Resend's logs, her newsletter engagement lives in Mailchimp, and her support reply lives in Gmail. Three systems, three copies of "Dana," zero shared context. When she emails support, the agent has no idea she opened last week's campaign or that her last invoice bounced.

In a unified D1 dataset, all three are rows keyed to the same contact. The support thread sits next to the transactional history and the campaign engagement. You can answer "has this person paid, and did they read the last announcement?" with a join, not a tab-switching expedition across three SaaS dashboards. That is the structural payoff of hosting the inbox on the same data as everything else, and it is hard to retrofit onto separate vendors.

What makes it smarter than a folder?

Interpreter verdicts and an AI agent operate on the same data the inbox shows, so triage is built in rather than bolted on. Two features turn the inbox from a passive reader into something active.

Email interpreters classify inbound mail as it arrives, with a mix of algorithmic rules and LLM passes, each backed by its own eval suite. An interpreter can flag a message as an OTP code, a complaint, a bounce, or whatever categories you define, and the verdict surfaces in the inbox next to the message. Instead of reading every mail to triage it, you see the classification first. The rule mechanics and eval approach are in interpreter verdicts surfaced in the inbox.

The AI agent triages alongside the UI, reading the same inbox over the same data. It is built on the Vercel AI SDK and can search, summarize, label, and draft replies across your mail. Because it works on your D1 data, it is operating on the unified contact record described above, not a thin slice. The agent and how it connects (including over MCP) is covered in the AI agent that triages alongside the inbox. The inbox UI is, in effect, an agent substrate: the same dataset a human reads is the one the agent acts on.

How do you set up a self-hosted webmail inbox?

Scaffold the stack, bind the inbox domain, configure inbound routing, and invite your team. Here is the procedure end to end.

Scaffolding and provisioning are two commands. tinbox init copies the project template and brands it to your domain; tinbox setup --deploy provisions the Cloudflare resources and ships the Worker:

npx tinbox init yourdomain.com
cd yourdomain
tinbox setup --deploy

Trimmed setup output:

  + D1 database     tinbox-yourdomain-db
  + R2 bucket       tinbox-yourdomain-mail
  + Queues          tinbox-yourdomain-newsletter, tinbox-yourdomain-projection
  + Worker          tinbox-yourdomain       (webmail SPA + API + email handler)

  πŸŽ‰ Deployed.
  next:
    1. enable Email Routing for yourdomain.com + add a catch-all -> tinbox-yourdomain
    2. open the deployed worker URL and create the first account

The full flow β€” what init scaffolds, what setup provisions, and the one dashboard routing step β€” is in the npx tinbox init walkthrough. Open the deployed inbox in a browser and create the first account; auth is passkey-primary, so there is no password to set or leak.

Add your team from inside the inbox: the console's Members view issues an invite link per teammate (or several at once). Each invitee opens their link, registers a passkey on first sign-in, and is in β€” no shared passwords, and they read the same inboxes on the same domain. For the broader set of capabilities a shared inbox should ship with beyond reading and replying, see role-based access for a team inbox.

Why is my self-hosted inbox empty? (failure modes)

If the inbox loads but shows no mail, inbound routing or DNS is not configured yet: the UI works, but nothing is feeding D1. This is the single most common "it's broken" report, and it is almost never the inbox.

symptom:  inbox UI loads at https://mail.yourdomain.com, signs in fine,
          but the thread list is empty and a test email never appears.

Walk it in this order:

  • Email Routing not enabled. If you skipped step 2, Cloudflare never accepts mail for the domain. Enable Email Routing in the dashboard and let it add the MX and SPF records. Without MX records, senders cannot even find your domain.
  • No rule pointing at the Worker. Routing can be enabled but still forward elsewhere. The address (or catch-all) must have a "Send to a Worker" action targeting tinbox-yourdomain. Mail accepted but never reaching your code almost always means the rule points at the wrong destination. The how inbound mail lands in the inbox walkthrough covers this exact diagnosis.
  • Domain not verified / DNS not propagated. A freshly added domain may not have its records live yet. Confirm the MX records resolve before testing.

Fix the routing, send a test message, and the thread appears in the inbox within seconds, because now D1 is actually being written. Two other team-level snags worth knowing:

  • Invite link issues. An invite link is single-use and tied to the address. If a teammate's passkey registration fails (browser without a platform authenticator, for instance), re-issue the invite rather than reusing the consumed link.
  • Wrong hostname. If mail.yourdomain.com does not resolve, the DNS binding in step 2 is missing. The Worker is deployed; the hostname just is not pointed at it yet.

Where does Gmail still win?

Gmail still beats a self-hosted inbox on mobile apps, spam filtering at Google scale, search refinement, and ecosystem maturity, and it would be dishonest to pretend otherwise. Gmail is an excellent product with a decade and a half of polish.

Be clear-eyed about the trade:

  • Mobile. Gmail has first-class native iOS and Android apps with push, offline, and years of UX work. A self-hosted webmail inbox is a responsive web app; it is usable on a phone, but it is not a native client with the same polish.
  • Spam filtering. Google filters spam against signals from billions of mailboxes. No self-hosted setup matches that scale. You get the filtering Cloudflare and your own rules provide, which is real but not Google-grade.
  • Search refinement and ecosystem. Gmail's operators, integrations, and the broader Google Workspace ecosystem are mature in ways a focused inbox is not trying to match.

The pitch is not "this is better than Gmail at being Gmail." It is ownership and unification: your mail in your own D1, on your own domain, in your own Cloudflare account, sharing one dataset with your sender and newsletter, with an agent that reads it. Where a self-hosted inbox does pull ahead is the smart features that come from owning the data, which is the angle in the AI inbox features Gmail won't give you. If those properties matter more to you than native mobile apps and Google-scale spam filtering, the trade is worth it. If they don't, Gmail is genuinely a fine answer, and you should keep using it.

This is the human-facing capstone of the owned stack: the same database that powers transactional sending and campaigns also powers a real inbox you read in a browser on your domain. For the whole picture of how the inbox fits the rest, see the inbox as one part of the owned stack.

Deploy this yourself: npx tinbox init <domain> then tinbox setup --deploy β€” the full walkthrough. The docs cover enabling Email Routing and inviting your team.

Frequently asked questions

Is there a real inbox UI, or just an email API?

There is a real inbox UI. Tinbox ships a threaded webmail client (read, search, compose, reply) that runs on your own domain in your own Cloudflare account. It is a single-page app served by the same Worker that holds your data, not just a REST or tRPC surface you have to build a front end against.

Where does the mail in a self-hosted webmail inbox come from?

Inbound mail arrives through Cloudflare Email Routing, which hands each message to a Worker's email() handler that parses the MIME and writes structured fields into D1 (SQLite) plus the raw .eml into R2. You can also import existing mail from Gmail, IMAP, or an mbox file. Until Email Routing and DNS are configured, the inbox loads but stays empty.

Can my whole team use the self-hosted inbox?

Yes. Auth is passkey-primary, and you add teammates with invite links. Each person registers a passkey on first sign-in, so there are no shared passwords. The team reads the same inboxes on the same domain.

How does search work in a self-hosted webmail inbox?

Search runs on SQLite FTS5, a full-text index over message bodies, subjects, and participants stored in D1. Queries return matching messages ranked by relevance. Because the index lives in your own D1 database, search never leaves your Cloudflare account.

When does Gmail still beat self-hosted webmail?

Gmail wins on mobile apps, spam filtering at Google scale, search refinement, and a decade of ecosystem integrations. A self-hosted inbox trades that maturity for ownership: your mail, your domain, your account, and one dataset shared with your sender and newsletter.

Can I reply to mail from the self-hosted inbox?

Yes. Compose and reply send through your own HTTPS-based sender on the same Cloudflare account, because Workers cannot open outbound port 25 for direct-to-MX SMTP to send directly. The sent message is threaded back into the same conversation you replied from.