Deployment
Publish your aliases to Cloudflare with a single mm deploy that handles the Worker, your inboxes, and the catch-all for you.
Cloudflare Requirements
- Cloudflare account — Free or paid.
- A domain managed by Cloudflare DNS — The base domain must be the zone itself or a subdomain of it.
- Email Routing enabled — Enable it once under Email > Email Routing so Cloudflare adds the MX and SPF records.
- An API token — With the three permissions listed below.
info
Enabling Email Routing changes your DNS, so Mailmask leaves that step to you. If it isn't enabled, deploy stops with a message pointing to the dashboard.
API Token Permissions
Create a custom token at dash.cloudflare.com/profile/api-tokens with these permissions.
| Permission | Why it is needed |
|---|---|
| Account > Workers Scripts > Edit | Publishes the Worker. |
| Account > Email Routing Addresses > Edit | Registers each destination inbox and checks its verification. |
| Zone > Email Routing Rules > Edit | Points the zone's catch-all rule at the Worker. |
Under Account Resources, select your account. Under Zone Resources, select the zone that holds your base domain.
Providing the Token
- Interactive deploy — Choosing Deploy in the
mmmenu walks you through creating a token, verifies it, and saves it asCLOUDFLARE_API_TOKENin a.envfile in your config directory. - Direct command —
mm deployreadsCLOUDFLARE_API_TOKENfrom the environment or that.envfile. It stops with an error instead of prompting when no valid token is found.
If the token is missing a permission, deploy lists exactly which ones to add. In the interactive menu, it waits while you update the token and then retries.
What Deploy Does
- Authenticates — Confirms the API token is valid.
- Validates — Checks the config and stops if anything is wrong.
- Finds the zone — Locates the Cloudflare zone for your base domain and verifies the token's permissions.
- Checks Email Routing — Confirms Cloudflare Email Routing is enabled on the zone.
- Registers destinations — Adds any new destination to Email Routing, which triggers a verification email, and lists the ones still unverified.
- Generates
wrangler.toml— Writes the Worker configuration with your settings, destinations, and aliases. - Publishes the Worker — Runs
wrangler deploy. - Points the catch-all — Sets the zone's catch-all rule to send mail to the Worker, unless it already does.
- Prints a summary — Lists every alias with its full address, destination, and status.
warning
Verifying Destinations
Cloudflare only forwards to verified inboxes. Until you click the link in the verification email, mail for any alias that uses that destination can't be delivered.
Run mm deploy again after verifying to confirm the warning is gone.
Updating Aliases
Every change to the config reaches Cloudflare on the next deploy. A typical retire-and-redeploy looks like this:
# Stop accepting mail at an address that started getting spam.
mm alias disable velvet-harbor-42
# Ship the change.
mm deploy
Worker Exposure
The generated configuration turns off the workers.dev address and preview URLs. The Worker only handles inbound email, and any web request to it returns 404.