
mailboxer
dev.mailboxer/mailboxer
Your own email, calendars and contacts (IMAP, SMTP, CalDAV, CardDAV) for any agent.
Documentation
mailboxer
mailboxer connects your email, calendars, contacts, and reminders to any agent through an always-on MCP. It is designed for people who want to use their own accounts without deploying and configuring several separate services. iCloud works out of the box, and mailboxer automatically discovers standard IMAP, SMTP, CalDAV, and CardDAV settings for other providers when available.
Each MCP connection serves one email account. Connect the first one at /mcp. For each other account, add a connection at a named address such as /mcp/work or /mcp/personal (lowercase letters, digits and dashes) and sign in to that account. Some clients, including Claude, refuse or silently drop a second connection with the same URL, so a distinct path is what lets them keep both. Tools always use the account signed in on their connection; get_account returns its address, the connection name, and the available services.
pi mcp add mailboxer --url https://YOUR-WORKER/mcp
pi mcp login mailboxer
pi mcp add mailboxer-work --url https://YOUR-WORKER/mcp/work
pi mcp login mailboxer-work
Signing in always takes the account's current password (for iCloud, any valid app-specific password) and checks it live against the mail servers. Use a new one to reconnect after revoking or forgetting the old one: it replaces the stored password for every connection to that account.
Agents read https://YOUR-WORKER/llms.txt, an llms.txt document generated for each instance: what mailboxer is, how to connect each agent (Claude Code, Codex, Pi, ChatGPT, Claude, others), OAuth discovery details, and the tool list. The landing page's setup prompt points there. The old address /agent-setup/prompt.md serves the same document.
Mail events
mailboxer pushes mailbox changes to MCP clients instead of making agents poll. Each IMAP mailbox is an MCP resource, mailboxer://mailbox/{name} (the name is URL-encoded, so Archive/2026 becomes mailboxer://mailbox/Archive%2F2026). Reading it returns the mailbox's live counters (messages, unseen, UIDNEXT, UIDVALIDITY) and metadata for its 10 most recent messages. resources/list advertises the inbox.
Clients on MCP protocol revision 2026-07-28 open a subscriptions/listen stream and name up to three mailbox URIs:
{
"jsonrpc": "2.0",
"id": 1,
"method": "subscriptions/listen",
"params": { "notifications": { "resourceSubscriptions": ["mailboxer://mailbox/INBOX"] } }
}
While the stream is open, the Worker keeps one IMAP IDLE connection per subscribed mailbox (or polls STATUS every minute on servers without IDLE) and sends notifications/resources/updated with the mailbox URI whenever mail arrives, is expunged, or changes flags. The notification carries only the URI, so message content is always fetched through a normal, scope-checked read. Subscriptions need the mail.read scope. Watchers stop as soon as the client disconnects, and closing the stream closes the IMAP connections. 2025-era clients are served statelessly and do not see the resources.subscribe capability.
Deploy it yourself
Deploy mailboxer to your own Cloudflare account with the button below. Cloudflare copies this repository to your GitHub or GitLab account, creates the Worker and its storage, and asks for one value: the encryption key. Email credentials are added later through mailboxer's sign-in page and are never committed to the repository.
When the button asks for MAIL_CREDENTIALS_ENCRYPTION_KEY, paste the output of openssl rand -hex 32. Everything else has a working default.
What you need
- A Cloudflare account. The Workers Free plan is enough to sign in and use the tools. Mail events keep a stream open, and the Free plan's 10 ms CPU limit per request ends those streams after roughly 15 to 20 minutes; on Workers Paid they stay open for a few milliseconds of CPU per 10 minutes.
- A GitHub or GitLab account for the copy of the repository that the button creates. Pushing to it redeploys the Worker.
- Nothing else: no database, no domain, no email provider account. The Worker is reachable at
https://<worker-name>.<your-subdomain>.workers.devuntil you add a custom domain.
Settings
Secrets are set in the Cloudflare dashboard (Workers & Pages > your Worker > Settings > Variables and Secrets, type Secret) or with npx wrangler secret put NAME. Secrets survive later deployments from your repository; plain-text variables set in the dashboard do not, so always use the Secret type.
| Name | Required | What it does |
|---|---|---|
MAIL_CREDENTIALS_ENCRYPTION_KEY | Yes | Encrypts stored mail passwords and signs sign-in state. At least 32 characters; generate it with openssl rand -hex 32. Changing it makes every stored password unreadable, so each account then has to sign in again. |
OPERATOR_NAME | No | Your name or your organisation's, shown as the operator on the privacy, terms and support pages. |
CONTACT_EMAIL | No | Address for support, privacy and deletion requests, shown on the same pages. |
OPERATOR_REGISTRATION | No | Legal form, share capital and registration number, shown on the legal notice at /legal. |
OPERATOR_ADDRESS | No | Registered office, shown on the legal notice. |
PUBLICATION_DIRECTOR | No | Publication director, shown on the legal notice. |
MCP_REGISTRY_AUTH | No | Only for a public listing in the MCP Registry, see below. |
OPENAI_APPS_CHALLENGE | No | Only for publishing an app in ChatGPT: the domain verification token OpenAI gives you, served at /.well-known/openai-apps-challenge. |
Bindings are declared in wrangler.jsonc and created on the first deployment; there is nothing to set up by hand.
| Binding | Required | What it is |
|---|---|---|
OAUTH_KV | Yes | KV namespace for OAuth grants and encrypted account settings. |
METRICS | No | Workers Analytics Engine dataset mailboxer_metrics, see Observability. Without it, no metrics are written. |
AUTH_RATE_LIMITER | No | Workers Rate Limiting, 30 sign-in actions per minute per IP. Without it, only the per-address lockout applies. Rate limit namespaces are shared by every Worker in the account, so give each mailboxer instance on the same account its own namespace_id. |
CF_VERSION_METADATA | No | The deployed version ID, reported by /health/ready and in logs. |
Check the deployment
- Open
https://YOUR-WORKER/health/ready. It answers"status":"ok"when the KV namespace and the encryption key are in place, and HTTP 503 with the failing check otherwise. A missing or too short key shows as"encryptionKey":{"ok":false,"error":"not_configured"}: set the secret, then open the page again. - Open
https://YOUR-WORKER/: the landing page shows the MCP address of your instance. - Add
https://YOUR-WORKER/mcpto your agent and sign in with your email address and an app password. The privacy, terms and support pages at/privacy,/termsand/supportname you onceOPERATOR_NAMEandCONTACT_EMAILare set.
Deploy from the command line
Without the button, clone this repository and deploy it with Wrangler. Wrangler creates the KV namespace and the other resources on the first deployment.
git clone https://github.com/mailboxer-dev/mailboxer.git
cd mailboxer
npm ci
npx wrangler login
npx wrangler deploy
openssl rand -hex 32 | npx wrangler secret put MAIL_CREDENTIALS_ENCRYPTION_KEY
To try it locally first, copy .dev.vars.example to .dev.vars, fill in the key, and run npm run dev. The local instance listens on http://localhost:8787.
Upgrading your installation
The Deploy to Cloudflare button documentation explains how the button creates a user-owned repository and connects it to Cloudflare. That repository is the source of truth for your installation. Sync updates from mailboxer-dev/mailboxer, review them, and update the production branch; the existing Cloudflare Workers Builds integration then builds and deploys the Worker.
The examples below assume that the installation repository and its production branch are named main. Replace main if you use a different production branch.
Changes that need action
Most updates need nothing beyond the merge. These ones do:
- December 2026. Sign-in records written before October 2026 are no longer read: accounts connected that long ago have to sign in again, once, and old connections ask the agent to reconnect. The update also adds the
METRICSandAUTH_RATE_LIMITERbindings, which are created on deployment, and the optionalOPERATOR_NAMEandCONTACT_EMAILsecrets, which you should set before others use your instance (see Settings). Accounts other than the first are now connected at/mcp/<name>, for example/mcp/work.
Manual upgrade
Clone the repository created for your installation, add the upstream repository, merge its main branch, run the checks, and push the result:
git clone https://github.com/<YOUR_GITHUB_USERNAME>/<YOUR_INSTALLATION_REPOSITORY>.git
cd <YOUR_INSTALLATION_REPOSITORY>
git remote add upstream https://github.com/mailboxer-dev/mailboxer.git
git fetch upstream main
git switch main
git pull --ff-only origin main
git merge --no-edit upstream/main
npm ci
npm run type-check
npm run lint
npm test
git push origin main
If you already have an upstream remote, update it with git remote set-url upstream https://github.com/mailboxer-dev/mailboxer.git instead of adding it. A merge conflict or failed check is a stop point: resolve the conflict or fix the check, rerun the checks, and only then push. Use git merge --abort to abandon an in-progress merge. If your repository requires pull requests, push the merge to a topic branch and merge that pull request into main instead.
When resolving conflicts, preserve the values generated for your installation in wrangler.jsonc, especially the Worker name, KV namespace IDs under kv_namespaces, and any account- or environment-specific settings. Do not replace those values with the upstream defaults. Never commit MAIL_CREDENTIALS_ENCRYPTION_KEY, .dev.vars, other runtime secrets, or mailbox credentials; keep the encryption key in the Worker's Cloudflare secret configuration and manage mailbox credentials through mailboxer's sign-in flow.
Automated weekly upgrades with GitHub Actions
For a GitHub installation repository, save the following as .github/workflows/sync-upstream.yml. It runs every Monday at 06:00 UTC and can also be started with Run workflow. The dedicated upstream-sync branch is recreated from the latest main, so an existing open pull request is updated rather than duplicated. The workflow runs the same repository checks before pushing that branch and opening a review pull request.
name: Sync mailboxer upstream
on:
schedule:
- cron: "0 6 * * 1"
workflow_dispatch:
permissions:
contents: read
concurrency:
group: mailboxer-upstream-sync
cancel-in-progress: false
jobs:
validate:
runs-on: ubuntu-latest
outputs:
has_changes: ${{ steps.merge.outputs.has_changes }}
upstream_sha: ${{ steps.merge.outputs.upstream_sha }}
steps:
- name: Check out installation repository
uses: actions/checkout@v6
with:
fetch-depth: 0
persist-credentials: false
- name: Fetch upstream
run: |
git remote add upstream https://github.com/mailboxer-dev/mailboxer.git
git fetch --no-tags upstream main
git fetch --no-tags origin main
- name: Merge upstream into sync branch
id: merge
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git switch -C upstream-sync origin/main
git merge --no-edit upstream/main
echo "upstream_sha=$(git rev-parse upstream/main)" >> "$GITHUB_OUTPUT"
if git diff --quiet origin/main...HEAD; then
echo "has_changes=false" >> "$GITHUB_OUTPUT"
else
echo "has_changes=true" >> "$GITHUB_OUTPUT"
fi
- name: Install dependencies
if: steps.merge.outputs.has_changes == 'true'
run: npm ci
- name: Type-check
if: steps.merge.outputs.has_changes == 'true'
run: npm run type-check
- name: Lint
if: steps.merge.outputs.has_changes == 'true'
run: npm run lint
- name: Test
if: steps.merge.outputs.has_changes == 'true'
run: npm test
publish:
needs: validate
if: needs.validate.outputs.has_changes == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Check out installation repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Fetch validated upstream revision
run: |
git remote add upstream https://github.com/mailboxer-dev/mailboxer.git
git fetch --no-tags upstream "${{ needs.validate.outputs.upstream_sha }}"
git fetch --no-tags origin main
if git ls-remote --exit-code --heads origin upstream-sync >/dev/null 2>&1; then
git fetch --no-tags origin upstream-sync
fi
- name: Recreate validated sync branch
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git switch -C upstream-sync origin/main
git merge --no-edit "${{ needs.validate.outputs.upstream_sha }}"
- name: Push sync branch
run: git push --force-with-lease --set-upstream origin upstream-sync
- name: Create or update pull request
env:
GH_TOKEN: ${{ github.token }}
run: |
if [ "$(gh pr list --base main --head upstream-sync --state open --json number --jq 'length')" -eq 0 ]; then
gh pr create \
--base main \
--head upstream-sync \
--title "chore: sync with mailboxer upstream" \
--body "Review upstream changes before merging. Merging into main triggers the existing Cloudflare Workers Build."
else
echo "An open upstream sync pull request already exists; the branch was updated."
fi
The validation job is read-only and does not persist GitHub credentials while it installs or executes upstream code. Only after that job passes does a fresh publishing job receive contents: write and pull-requests: write, merge the exact upstream commit that was validated, and update the pull request. In the installation repository, go to Settings > Actions > General > Workflow permissions and enable Allow GitHub Actions to create and approve pull requests; an organization policy may prevent changing this setting. The workflow uses only the automatically provided GITHUB_TOKEN; it does not need a Cloudflare API token, account credentials, or mailbox secrets, and it never deploys directly. Merging the reviewed pull request into main is what triggers the Workers Build. If there are no upstream changes, the workflow exits without pushing a branch or creating a pull request. If the upstream merge conflicts or any check fails, the workflow stops before updating the sync branch or pull request, leaving the update for manual resolution.
Public pages and operator details
Every instance serves its own documentation, privacy policy, terms, support and legal notice pages at /docs, /privacy, /terms, /support, and /legal, plus /robots.txt and /sitemap.xml. The landing page and these pages are rendered on the server, so they can be read without JavaScript.
The legal pages describe what the software stores. Set OPERATOR_NAME and CONTACT_EMAIL (see Settings) to name yourself as the operator and give an address for support and deletion requests. For the legal notice at /legal, also set OPERATOR_REGISTRATION, OPERATOR_ADDRESS and PUBLICATION_DIRECTOR. Without them, the pages refer to "the person who runs" the instance's host and show no contact address. Review the policy and terms before offering your instance to other people: you are responsible for how it handles their data.
Data retention
People can delete their saved account themselves, effective at once. The /delete-account page asks for the address and the password that works for it today, finds the servers for that address the same way sign-in does, and logs in to the IMAP server to check it; the saved password and saved servers are never used. It then deletes every record saved for that address, found through a keyed-hash address index (mail:account-address:v1:*, one key per record), and revokes their grants. Records saved before that index existed are indexed by the scheduled sweep's first full pass. From a connected agent, the delete_account tool deletes the connection's own record after the agent passes the connected address as confirmation.
A daily cron trigger deletes accounts that have not been used for 365 days: no sign-in and no token issued or refreshed for a connected agent. Deleting an account removes its encrypted record, its address index entry, and every OAuth grant and token issued for it. Accounts saved before this existed start their year on the first run. The same job deletes keys left by earlier versions that no code reads (mail:account-vault:v2:*, mail:account-index:v2:*, mail:account-email-index:v2:*).
Listing in the MCP Registry
Self-hosted instances do not need this. server.json describes the hosted instance at mailboxer.dev for the official MCP Registry, under the dev.mailboxer/* namespace. Publishing proves ownership of the domain over HTTP:
- Generate a key pair:
openssl genpkey -algorithm Ed25519 -out key.pem, and keepkey.pemout of the repository. - Set the public record as a secret:
npx wrangler secret put MCP_REGISTRY_AUTHwith the valuev=MCPv1; k=ed25519; p=<PUBLIC_KEY>, where<PUBLIC_KEY>isopenssl pkey -in key.pem -pubout -outform DER | tail -c 32 | base64. The Worker then serves it at/.well-known/mcp-registry-auth. - Log in and publish:
mcp-publisher login http --domain mailboxer.dev --private-key <PRIVATE_KEY_HEX>(fromopenssl pkey -in key.pem -noout -text | grep -A3 priv | tail -n +2 | tr -d ' :\n'), thenmcp-publisher publish.
Bump version in server.json for each new listing.
Technical overview
mailboxer is a stateless TypeScript Cloudflare Worker with a bundled OAuth server and MCP endpoint. It stores OAuth records and encrypted account settings in Cloudflare KV, while messages, searches, calendars, and contacts are always fetched live from IMAP, SMTP, CalDAV, or CardDAV. It uses no database, mailbox cache, search index, Durable Object, or persistent protocol connection.
Observability and monitoring
Workers Observability (logs and traces) is enabled in wrangler.jsonc. On top of the automatic traces, mailboxer adds:
-
Spans around every MCP tool call, IMAP and SMTP command, DAV request, and account discovery step, with
mcp.tool.outcome,mcp.tool.duration_ms, anderror.typeon tool spans. -
Structured logs: one
http_requestline per request (route bucket, method, status, duration) and onemcp_tool_completedline per tool call (tool, outcome, duration, error class, hashed account key). Failures keep the existing redacted*_failedevents. No log line carries message content, addresses, hostnames, or credentials. -
Metrics in the Workers Analytics Engine dataset
mailboxer_metrics(bindingMETRICS, optional):blob1kind (httportool),blob2route bucket or tool name,blob3outcome,blob4error class,blob5HTTP method,blob6Worker version,double1duration in ms,double2HTTP status. For example, the tool error rate over the last hour:SELECT blob2 AS tool, SUM(_sample_interval) AS calls, sumIf(_sample_interval, blob3 = 'error') AS errors FROM mailboxer_metrics WHERE blob1 = 'tool' AND timestamp > NOW() - INTERVAL '1' HOUR GROUP BY tool ORDER BY errors DESC -
Readiness probe at
GET /health/ready: checks thatOAUTH_KVanswers and that the encryption key is configured, and returns HTTP 503 otherwise.GET /healthstays a plain liveness check.
No installation packages available.