Quickfix change destination email in email routing for many domains and accounts

Do you recommend using an email worker or the email routing api for this task? I have many domains 500+ on many accounts 40+ Each zone has email forwarding with the same destination email in the email routing setup. Could an email worker intercept all email forwarding rules for all zones in a specific account and forward them to a different email?
8 Replies
DarkDeviL
DarkDeviL4mo ago
From how I understand your use case, you can do whatever that suits you best of those two ways. Regardless of whether it is the normal email routing, or the worker, you just need the destination email address to be verified. With a worker, you can simply make the worker be a catch all, and everything will pass through the worker. The worker can then take care (based on various criteria) to distribute traffic accordingly, such as e.g. based on the destination like yo know from the classic email routing. For example by forwarding with various conditions, so if the destination was alfa@example.com, it could execute the forward to alfa@destination.eaxmple.com. And if the destination was bravo@example.com, it could execute the forward to bravo@destination.eaxmple.com, ... and so on).
GrN.dk
GrN.dk4mo ago
OK, sounds interesting, thank you. Would it be possible to create a single worker on an account that will catch all emails from all zones and then forward it to destination@example.com? I am having a bit trouble of finding a way that will forward all mails from all zones to a single email. The current scenario is that we are using email routing with forwarding from custom mails from all zones to a single destination address destinationA@example.com, but this needs to change to destinationB@example.com. Or just use a intercepting worker that will redirect/forward to destinationB@example.com, but I am unable to find any documentation regarding this approach. We usually use the API to update some of these things for DNS, not really for email routing at this point. So we where thinking of utilizing a worker instead as a quick fix. Thank you.
Aman Singh
Aman Singh4mo ago
Interesting approach. I think a worker has access to all zones, but I think you need to add some DNS records to each of your zones for the worker to be active. This can be done directly through the worker's trigger menu. You can automate this by creating a Python programme and making use of the cloudflare API with DNS access to add all those new DNS records to each of your zones in that cloudflare account. Once that is done, the worker will be able to route all your emails from various zones to your desired destination.
GrN.dk
GrN.dk4mo ago
Thank you for the feedback. If I need to add DNS records via the Cloudflare API, I might as well replace the current email routing forwarding rule with the correct email via the API. Or maybe I have misunderstood something. And where can I read about how to setup a worker like that?
DarkDeviL
DarkDeviL4mo ago
I believe the email workers are per zone, and must eventually be added individually under each zone (domain) that you have on Cloudflare. There are several examples out here for what you can do with email workers. Forward from one address to multiple (verified) addresses could be something like: https://community.cloudflare.com/t/email-worker-to-forward-to-multiple-emails/474377/4 Or even less advanced: https://community.cloudflare.com/t/e-mail-routing-to-multiple-addresses/523842/4
nir4
nir44mo ago
he could also have one master domain that all of them forward to, then it's bound to a worker
DarkDeviL
DarkDeviL4mo ago
While stacking forwarding domains up on each other, and forwarding from one email routing/worker domain to another isn't completely impossible, it would cause a lot of headache when you're troubleshooting eventual issues, such as e.g. when email deliveries are failing.
GrN.dk
GrN.dk4mo ago
Thank you all for the suggestions! I think the best and most robust solution for our use case is to replace destination address in the forward email route via API for each zone in each account.