Skip to content

Support multiple domains per inbox#49

Open
PierreFouquet wants to merge 1 commit into
cloudflare:mainfrom
PierreFouquet:multi-domain-support
Open

Support multiple domains per inbox#49
PierreFouquet wants to merge 1 commit into
cloudflare:mainfrom
PierreFouquet:multi-domain-support

Conversation

@PierreFouquet

Copy link
Copy Markdown

Summary

Resolves #8 ("Connect Multiple domain in 1 worker?").

While investigating, I found that a single instance can already serve multiple domains — it was just undocumented, which is why it was assumed unsupported:

  • GET /api/v1/config already splits the DOMAINS var on commas (workers/index.ts).
  • The New Mailbox dialog already renders a domain Select when more than one domain is configured (app/routes/home.tsx).
  • Sending (validateSender) and receiving (receiveEmail) are domain-agnostic, and EMAIL_ADDRESSES can already span domains.

This PR makes multi-domain a documented, first-class feature and adds a matching backend guard.

Changes

  • workers/index.ts — add a parseDomains() helper (reused by /api/v1/config), and reject mailbox creation on domains outside the configured DOMAINS, mirroring the front-end picker. Explicit EMAIL_ADDRESSES entries bypass the check (they are the authoritative allow-list and may legitimately span domains), and an empty DOMAINS imposes no restriction — so existing behavior is preserved.
  • README.md — new "Using multiple domains" section; clarified the singular "your domain" wording.
  • wrangler.jsonc — comments documenting that DOMAINS accepts a comma-separated list and that EMAIL_ADDRESSES may span domains.
  • package.json — expanded the deploy-time DOMAINS binding description.

No change to send/receive behavior.

How to use

Set DOMAINS to a comma-separated list and add a catch-all Email Routing rule (and verified sending) per domain:

"DOMAINS": "example.com,another.com"

Testing

Verified locally with a multi-domain config (DOMAINS="example.com,another.com") injected via a local-only Wrangler config (per the approach in #44), running npm run dev:

Check Result
GET /api/v1/config {"domains":["example.com","another.com"],"emailAddresses":[]}
Create hello@example.com (1st domain) 201
Create hi@another.com (2nd domain) 201
Create x@notconfigured.com 400 "Mailbox domain must be one of the configured DOMAINS"
npm run typecheck passes ✅

🤖 Generated with Claude Code

A single instance can already serve multiple domains by setting DOMAINS to a
comma-separated list: the /api/v1/config endpoint splits it, and the New Mailbox
dialog renders a domain picker when more than one is configured. This was
undocumented, so users assumed it was unsupported (issue cloudflare#8).

Make it a documented, first-class feature and add a matching backend guard:

- Add a parseDomains() helper and reuse it in /api/v1/config.
- Reject mailbox creation on domains outside the configured DOMAINS, mirroring
  the front-end picker. Explicit EMAIL_ADDRESSES entries bypass the check, so the
  auto-create flow (which may span domains) is unaffected. No DOMAINS configured
  means no restriction, preserving existing behavior.
- Document multi-domain setup in the README ("Using multiple domains"),
  wrangler.jsonc, and the deploy-time DOMAINS binding description.

Closes cloudflare#8

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Connect Multiple domain in 1 worker?

1 participant