EmailRouting
Enable and configure email routing for your Cloudflare zone to start receiving and routing emails sent to your domain.
CAUTION
Email Routing resources do not work with wrangler login
(OAuth tokens) due to permission limitations. You must use an API token instead with the following scopes:
- Zone:Read - to read zone information
- Zone:Edit - to manage email routing settings
See the Cloudflare Auth guide for details on setting up API token authentication.
Minimal Example
Enable email routing for your domain:
import { EmailRouting } from "alchemy/cloudflare";
await EmailRouting("my-email-routing", {
zone: "example.com",
enabled: true
});
Enable with Zone Resource
Use an existing Zone resource reference:
import { EmailRouting, Zone } from "alchemy/cloudflare";
const zone = await Zone("my-zone", {
name: "example.com"
});
await EmailRouting("my-email-routing", {
zone: zone,
enabled: true,
skipWizard: true
});
Configuration Options
Configure email routing with specific settings:
import { EmailRouting } from "alchemy/cloudflare";
await EmailRouting("custom-email-routing", {
zone: "example.com",
enabled: true,
skipWizard: true // Skip DNS setup wizard
});
Disable Email Routing
Disable email routing when no longer needed:
import { EmailRouting } from "alchemy/cloudflare";
await EmailRouting("my-email-routing", {
zone: "example.com",
enabled: false
});
Properties
Input Properties
zone
(string | Zone): Zone ID or Zone resource where email routing will be configuredenabled
(boolean, optional): Whether email routing should be enabled. Defaults totrue
skipWizard
(boolean, optional): Skip the DNS setup wizard when enabling email routing. Defaults tofalse
Output Properties
zoneId
(string): Zone ID where email routing is configuredenabled
(boolean): Whether email routing is enabledname
(string): Zone namecreated
(string): When email routing was createdmodified
(string): When email routing was last modifiedtag
(string): Zone tag
Prerequisites
Before enabling email routing, ensure:
- You have a Cloudflare zone configured for your domain
- Your domain's nameservers are pointed to Cloudflare
- You have the necessary DNS permissions for the zone
DNS Requirements
When email routing is enabled, Cloudflare automatically creates the necessary MX and TXT records for your domain. These records are required for email routing to function properly.
Next Steps
After enabling email routing:
- Create destination email addresses to receive forwarded emails
- Set up routing rules to define how emails are processed
- Configure a catch-all rule for unmatched emails