Agent-readable docs index: /llms.txt. Full docs in one file: /llms-full.txt. Download /docs.zip to grep all markdown files locally.

Self-host custom-domain mail on Cloudflare

Self-host a mailbox with one command, thanks to Cloudflare OAuth:
zele domain setup example.com
Authorize zele in Cloudflare. Setup configures Email Sending, Email Routing, an R2 bucket, and a small receive-only Worker in your account. You do not need Wrangler, a server API token, or an OAuth client secret.
In agent or non-interactive shells, setup returns the authorization link and continues in a background daemon for up to 10 minutes. Do not wrap it in a shell background process. Approve the browser request, then run zele domain status example.com. Status exits with code 1 while setup runs, after a failed or unfinished setup (it prints the error as last_setup), when receiving does not work, or when the domain has no local account. Interactive terminals stay attached and show progress. If your browser runs on another machine, open its final localhost redirect URL on the CLI machine to finish the callback.
Your account, your mailbox. Before the OAuth link, setup explains what it creates, where mail and credentials stay, and which permissions you grant. The CLI talks directly to Cloudflare. Neither your mail nor your OAuth credentials pass through zele servers. Review the open-source code before authorizing.

Before setup

Your domain must use an active Cloudflare DNS zone. Enable R2 in the Cloudflare dashboard first. R2 activation needs a payment method, even if your usage fits its free allowance.
Check existing mail delivery first. Email Routing needs Cloudflare MX records. If the domain's MX records point to another mail provider, setup stops before it changes anything. Use a subdomain with no MX records to keep your main mailbox unchanged:
zele domain setup mail.example.com --address support
Sending to arbitrary recipients requires Workers Paid. Workers Free permits only verified destination addresses. --receive-only skips sending onboarding. It does not reduce OAuth permissions or disable an existing sending configuration. Cloudflare bills your account for usage.

One account per domain

One account, one mailbox per address. Mail is filed under the address it was delivered to (the SMTP envelope recipient, never the To header), so every catch-all alias gets its own mailbox. hello@example.com is the default From address; use --address tommy or --address tommy@example.com to change it.
zele mail list --account alice@example.com # only alice: reads one R2 prefix zele mail list --account example.com # every mailbox, merged newest first zele domain status example.com # lists the mailboxes that have mail
No --account works like --account example.com. An address selects its mailbox even without a routing rule of its own, so you can read catch-all aliases. When another connected account has the exact same email, that account wins.
At the zone apex, setup enables catch-all by default. Existing literal address rules take precedence over catch-all. An enabled catch-all that sends elsewhere causes a conflict instead of being replaced. Subdomains use an address rule for --address, not a catch-all.
zele domain setup example.com --no-catch-all --address tommy zele mail list --account tommy@example.com
--no-catch-all creates or enables the selected address rule and disables zele's apex catch-all. It does not delete other literal rules. Previous address rules can remain after you change --address. Manage unwanted rules in Cloudflare. To switch back, run zele domain setup example.com --catch-all.

Where your mail goes

No zele-operated mail proxy or storage receives your mailbox contents. The CLI calls Cloudflare directly. We, the zele creators, do not receive or see your custom-domain emails through this architecture.
External sender ──> Cloudflare Email Routing ──> email Worker ──> your R2 bucket ^ Your computer: zele CLI ──> Cloudflare R2 API ─────────────────────────┘ │ list, download, save, move, delete v Cloudflare Email Sending API ──> external recipient send_raw All Cloudflare mail resources above belong to your Cloudflare account. zele.sh is not a mail proxy, storage service, or OAuth token relay for this feature.
The Worker receives mail while your computer is off. Its only handler is email(), which writes raw messages to R2. It has no mailbox HTTP API or shared secret. Sending does not pass through the Worker. The CLI builds MIME and calls Cloudflare's send_raw API, then saves a Sent copy in R2.
Mail does leave Cloudflare. External senders and recipients exchange it with Cloudflare. The CLI downloads messages to your computer and parses them locally. Attachments you save remain on disk. A terminal, script, or AI agent that runs zele can retain its output under its own rules. This is not end-to-end encryption.
Local credentials and domain settings live in ~/.zele/sqlite.db, alongside records of messages shown by mail read. Credentials are unencrypted and protected by file permissions. The Cloudflare client currently downloads message content on each read rather than caching it in the local Thread table. Other connected providers can have local mail caches in the same database.
This differs from free @zele.sh inboxes, which use zele-operated storage. See the privacy policy for both services.

Permissions and trust

No lock-in to zele. You own the Cloudflare resources and your domain's routing. Messages are raw MIME, a standard email format, not a zele-only database. Download the R2 objects as .eml files to import them into another mail tool. To move delivery to another provider, change your domain's routing and DNS records. Moving providers does not require access to a zele-operated service.
OAuth uses PKCE and a registered public-client ID, not an embedded server API token or client secret. Authorization and token refresh go directly to Cloudflare. The browser returns to http://localhost:8089 on the machine running setup.
Setup requests these scopes:
ScopeUsed for
zone.readFind the active zone and its account
zone-settings.writeConfigure Email Routing DNS
email-routing-rule.writeCreate, inspect, and remove routing rules
email-sending.writeOnboard the sending domain and send mail
workers-scripts.writeDeploy the receiving Worker and inspect its version
workers-r2.writeCreate the bucket and list, read, write, or delete mail
offline_accessRefresh access without a new browser consent each time
These are not mailbox-only permissions. Depending on the resources you authorize, the grant can allow changes to other Workers, R2 data, routing, and zone settings. You trust the installed CLI and its dependencies with that access. Account administrators can restrict OAuth applications. Revoke zele's grant in Cloudflare to stop future authorized API access; existing routing and the Worker remain until you remove them.

Updates and another machine

Run setup again after a zele upgrade. A rerun keeps the live routing mode: address-only routing stays address-only, so a plain rerun never widens it to catch-all. --receive-only is not saved; domain status prints the update command with it when sending is off:
zele domain status example.com zele domain setup example.com --receive-only
Setup finds shared resources in your Cloudflare account. The Worker and bucket are both named zele-domain-mail. The ZELE_WORKER_VERSION binding identifies the Worker. The .zele object identifies the bucket. Setup refuses a foreign Worker or nonempty unmarked bucket. An empty unmarked bucket can be adopted.
Worker versions are separate from zele versions. Setup uploads a missing or older Worker and refuses to downgrade a newer one. domain status checks the deployed version. Inbox listings can warn from version metadata on stored messages; that warning is not a live deployment check.
On a second machine, install the same or a newer zele and run setup with the same intended flags. It uses the existing remote mailbox and creates a separate OAuth grant locally. Cloudflare rotates refresh tokens. Do not copy a grant for simultaneous use on two machines. Concurrent token refreshes by processes on one machine can still require a new login. Read-before-reply records are local to each machine.

Mail commands and limits

Core mail commands work with --account hello@example.com: list, read, search, send, reply, forward, archive, trash, untrash, attachment list/get, and watch. New mail goes out as the selected address and its Sent copy is filed in that mailbox; with --account example.com that is the default address. --from can set any address on the domain as the From header, but the Sent copy stays in the selected mailbox. Replies and forwards go out as the mailbox of the original message: the address it was delivered to, or the address a Sent message was filed under. The To header is never used for this, because the sender controls it.
zele mail search invoice --account hello@example.com zele mail list --account hello@example.com --folder sent --filter invoice zele mail watch --account hello@example.com --filter invoice --timeout 600
Search is a case-insensitive substring match with a small Gmail-like syntax. All terms must match:
TermMatches
from:annsender name or address
to:sales@example.comTo, Cc, or the delivered address
deliveredto:sales@example.comonly the delivered address (catch-all aliases)
subject:"order 42"subject
invoiceany of the above
There is no body search, date, unread, or Boolean operator support. Other operators count as plain text. mail search checks the inbox. Use mail list --folder <folder> --filter <text> for another folder.
Filters run in the CLI, not in R2. R2 lists keys by prefix only, so each call reads 100 messages of one mailbox folder and zele filters their key index. A filtered request stops after about 1,000 messages per mailbox and returns a --page token that resumes right after the last message checked, so no match is skipped. A rare match in a big folder can take several pages.
SelectionR2 list calls per page
--account alice@example.com1 (unfiltered) or up to 10 (filtered), only under example.com/alice/
--account example.com1 to find the mailboxes, then the above for each mailbox
A domain-wide page merges the mailboxes by time. Its token is a timestamp, so the next page resumes every mailbox at the same point. deliveredto: skips mailboxes that cannot match before listing them.
There are no unread flags, stars, spam folders, drafts, labels, Gmail filters, or calendars. Each stored message is one list item, not an aggregated conversation. Available folders are inbox, sent, archive, and trash. Archive and trash download, upload, and delete an object. IDs look like alice:inbox:<stamp>. Mailbox and stamp never change, so an ID from before a move still works: zele checks the folder in the ID first, then the other folders of the same mailbox (up to three more list calls). An ID never resolves in another mailbox. Lists show the current folder. Trash has no automatic expiry.
Watch polls R2 every 15 seconds by default. Each poll lists the newest messages of each watched mailbox until it reaches ones it already saw, usually one call per mailbox whatever the filter (plus one call to find new mailboxes when watching the whole domain), and re-checks the last minute so a message stored a moment late is not missed. It is not a durable event log: mail moved out of the folder between polls is not reported. Cloudflare API rate limits apply to mail reads, moves, setup, and watch. Increase --interval when needed. A send with an uncertain outcome must not be retried automatically. A failed Sent copy after acceptance is a warning, not permission to resend.

R2 storage format

One bucket and Worker serve all configured domains in a Cloudflare account. Raw messages use keys like <domain>/<mailbox>/<folder>/<stamp>.<index>. <mailbox> is the lowercased local part of the address, with any byte outside a-z 0-9 . _ + - written as %XX, so a/b@example.com becomes a%2Fb. Received mail uses the SMTP envelope recipient, Sent copies the selected address. The Worker rejects a local part longer than 192 encoded characters instead of storing it. The timestamp counts down so listings put newest mail first. The base64url index is JSON with the fields lists and filters need, so listing never downloads bodies:
FieldSourceNotes
f, t, c, s, rFrom, To, Cc, Subject, In-Reply-To headerssender-controlled, cut to fit
mContent-Type1 when the message may have attachments
rtSMTP RCPT TO (received mail)the address on your domain that got the message
mfSMTP MAIL FROMreceived: the sender's bounce address, not verified; Sent copies: your From address
R2 keys hold 1,024 bytes, so the index gets what the key has left after the longest folder name. Envelope addresses are never cut, only dropped when a very long domain and mailbox leave no room; long headers are cut in listings and search, while the raw message remains intact. The REST API cannot write custom metadata, which is why the index lives in the key and survives moves. Encoding is not encryption; anyone with access to object names can decode those fields.

Mail apps (IMAP and SMTP)

Apple Mail, Thunderbird and phones can use the same mailboxes. It is off by default, and one command turns it on:
zele domain imap enable hello@example.com
Mail apps connect through the zele mail gateway, so this is the one case where your mail passes through a zele server, in memory only. Read Mail apps for the settings, app passwords and the data flow.

Stop receiving or remove mail

Removal affects all machines that use the domain because receiving rules are remote:
zele domain remove example.com # Permanent deletion of this domain's messages in every folder: zele domain remove example.com --delete-mail
Without --delete-mail, messages stay in R2. The command removes zele routing for the domain and the account on the current machine. It leaves the shared Worker and bucket, DNS records, Email Sending configuration, and OAuth grants. Other machines retain their local accounts. Non-interactive removal needs --force.
To finish decommissioning, revoke unused grants and remove unused Cloudflare resources in the dashboard. Do not delete the shared Worker or bucket while another domain uses them. Check DNS before you switch providers. Removing a local account alone does not stop Cloudflare from receiving mail.