Forward incoming email from approved senders to a verified destination address with Cloudflare Email Routing.
This starter uses an Email Worker to forward messages from a configurable sender allowlist to one verified destination. Its top-level Wrangler addresses configuration creates and maintains the Email Routing rules that invoke the Worker.
The Worker rejects messages from unapproved senders and fails closed when its destination or allowlist is missing.
It uses Email Routing for inbound delivery, a Workers email handler for forwarding decisions, and Workers Assets for the setup page.
- Email Routing receives a message for an address declared in
wrangler.jsonc. - The Worker compares the SMTP envelope sender with
ALLOWED_SENDERS. - Approved messages are forwarded to
FORWARD_TO; all other messages are rejected.
The template uses TypeScript without an application framework. Its ASSETS binding serves the static setup page, while the email event handler processes incoming messages.
- A domain on Cloudflare with Email Routing enabled.
- A verified Email Routing destination address.
Set these variables in wrangler.jsonc or during deployment:
ROUTE_ADDRESS: The Email Routing address shown on the setup page. Keep it in sync with the top-leveladdressesconfiguration.FORWARD_TO: The verified destination that receives forwarded messages.ALLOWED_SENDERS: A comma-separated list of sender addresses allowed to use the route.
Then uncomment the top-level addresses section in wrangler.jsonc and replace its example address:
Use "*@company.example" instead to route every otherwise-unmatched address on a domain to this Worker.
The setup page displays ROUTE_ADDRESS and FORWARD_TO, and indicates whether an allowlist exists without exposing its contents. It also warns while any email setting still contains example data.
The addresses field is managed by Wrangler. On deployment, Wrangler reconciles Email Routing rules for this Worker with the configured list. Review destructive changes carefully before accepting them.
npm install
npm run devThe local HTTP page shows setup guidance. To test incoming email handling, use the Email Routing local-development instructions in the Cloudflare documentation.
A live preview is provisioned during template review at email-routing-template.templates.workers.dev.
npm test
npm run checknpm run deployAfter deployment, send a message from an address in ALLOWED_SENDERS to one of the configured routing addresses.
