Enable Email Workers
Follow these steps to enable and add your first Email Worker. If you have never used Cloudflare Workers before, Cloudflare will create a subdomain for you, and assign you to the Workers free pricing plan.
-
Log in to the Cloudflare dashboard ↗ and select your account and domain.
-
Go to Email > Email Routing > Email Workers.
-
Select Get started.
-
(Optional) Enter a descriptive Email Worker name in Create a worker name.
-
In Select a starter, select the starter template that best suits your needs. You can also start from scratch and build your own Email Worker with Create my own. After choosing your template, select Create.
-
Now, configure your code on the left side of the screen. For example, if you are creating an Email Worker from the Allowlist template:
- In
const allow = ["friend@example.com", "coworker@example.com"];
replace the email examples with the addresses you want to allow emails from. - In
await message.forward("inbox@corp");
replace the email address example with the address where emails should be forwarded to.
- In
-
(Optional) You can test your logic on the right side of the screen. In the From field, enter either an email address from your approved senders list or one that is not on the approved list. When you select Trigger email event you should see a message telling you if the email address is allowed or rejected.
-
Select Save and deploy to save your Email Worker when you are finished.
-
Select the arrow next to the name of your Email Worker to go back to the main screen.
-
Find the Email Worker you have just created, and select Create route. This binds the Email Worker to a route (or email address) you can share. All emails received in this route will be forwarded to and processed by the Email Worker.
- Select Save to finish setting up your Email Worker.
You have successfully created your Email Worker. In the Email Worker’s card, select the route field to expand it and check the routes associated with the Worker.