making a worker to foward a message sent from 1 email to multiple emails

Hello im currently trying to figgure out a way to make a worker forward and email that a email adress recived and foward that to multiple other emails As im not tha experienced with workers i wanted to ask here what i could use to make that happen
11 Replies
Chaika
Chaika15mo ago
Sure, you can do this via email workers. If you just wanted a simple forward from one address to multiple: Add the addresses you want to use as destination addresses within email routing routes tab Create a new email worker from the Email Workers tab, select create your own, go to Quick Edit and replace with code like
export default {
async email(message, env, ctx) {
await message.forward("email1@gmail.com");
await message.forward("email2@gmail.com");
}
}
export default {
async email(message, env, ctx) {
await message.forward("email1@gmail.com");
await message.forward("email2@gmail.com");
}
}
Back in the Email Routing Routes tab, add a new custom address to send to that worker To test, send an email from an email address other then the two you are forwarding to (otherwise some providers like gmail will delete email they see as duplicates)
Nbc66
Nbc6615mo ago
Ahh alright so that was the issues i was trying to send it from the email im actually forwarding to lol Thank you so much this helps a ton
Chaika
Chaika15mo ago
ahh yea that can be confusing. Another potentially confusing thing is that currently Email Workers always show as "Dropped" in the email summary. If your worker errors out, it shows as "Delivery Failed".
Nbc66
Nbc6615mo ago
ok im having issues with this rn
mx.cloudflare.net gave this error:
Upstream error, please check https://developers.cloudflare.com/email-routing/postmaster for possible reasons why. RA6qfUtAb6oU
mx.cloudflare.net gave this error:
Upstream error, please check https://developers.cloudflare.com/email-routing/postmaster for possible reasons why. RA6qfUtAb6oU
@chaika.me
Chaika
Chaika15mo ago
Sounds like your worker is erroring out. Check your email summary tab to see if you have delivery failed, or tail your worker before you send an email. If I had to blindly guess, you probably are trying to forward to non-verified destinations, or some other runtime error
Nbc66
Nbc6615mo ago
i'll take a look at it
Nbc66
Nbc6615mo ago
looks like this is the main error
Chaika
Chaika15mo ago
Well that's not the actual error, it's just saying something is wrong with your Worker In the dashboard, if you navigate to your Worker and then the "Logs" tab, start log stream, send an email, and you should see the actual error
Nbc66
Nbc6615mo ago
Ok looks like i cant actually specify emails from cloudflaer itself but i have to use the verified email But i guess it works thank you for the help
Chaika
Chaika15mo ago
Yea, you need to add each email you want to forward to as destination addresses in email routing and verify them
Nbc66
Nbc6615mo ago
I mean as in i cant specify a routed email as in an example nbc66@customdomain.com that fowards to nbc66@someemail.com I guess i can send another requst to my allredy routed email from the email i made on cloudflaer lol But hey it works thank you again for the help