Edit Email Workers
Adding or editing Email Workers is straightforward. You can rename, delete or edit Email Workers, as well as change the routes bound to a specific Email Worker.
-
Log in to the Cloudflare dashboard ↗ and select your account and domain.
-
Go to Email > Email Routing > Email Workers.
-
Select Create.
-
(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.
-
Log in to the Cloudflare dashboard ↗ and select your account and domain.
-
Go to Email > Email Routing > Email Workers.
-
Find the Email Worker you want to rename, and select the three-dot button next to it.
-
Select Code editor.
-
Make the appropriate changes to your code.
-
Select Save and deploy when you are finished editing.
When you rename an Email Worker, you will lose the route that was previously bound to it. You will need to configure the route again after renaming the Email Worker.
-
Log in to the Cloudflare dashboard ↗ and select your account and domain.
-
Go to Email > Email Routing > Email workers.
-
Find the Email Worker you want to rename, and select the three-dot button next to it.
-
From the drop-down menu, select Manage Worker.
-
Select Manage Service > Rename service, and fill in the new Email Worker’s name.
-
Select Continue > Move.
-
Acknowledge the warning and select Finish.
-
Now, go back to Email > Email Routing.
-
In Routes find the custom address you previously had associated with your Email Worker, and select Edit.
-
In the Destination drop-down menu, select your renamed Email Worker.
-
Select Save.
The following steps show how to change a route associated with an Email Worker.
-
Log in to the Cloudflare dashboard ↗ and select your account and domain.
-
Go to Email > Email Routing > Email workers.
-
Find the Email Worker you want to change the associated route, and select route on its card.
-
Select Edit to make the required changes.
-
Select Save to finish.
-
Log in to the Cloudflare dashboard ↗ and select your account and domain.
-
Go to Email > Email Routing > Email workers.
-
Find the Email Worker you want to delete, and select the three-dot button next to it.
-
From the drop-down menu, select Manage Worker.
-
Select Manage Service > Delete.
-
Type the name of the Email Worker to confirm you want to delete it, and select Delete.