This tutorial explains how to send emails using Cloudflare Workers from any domain for free. For developers, it is kind of good news that you can now send email alerts from your worker scripts to any email address. You can also use any from address and it will just work fine. There is no domain verification or prior email verification required to send an email. Just construct an email body and then send it out.
Cloudflare Workers now support MailChannels Send API, which you use to send out emails. However, do not mistake this API for bulk emailing or spamming. It uses one of the best and powerful spam filters to prevent abuse of the API. And when I say that you will be able to send emails from any domain, do not take it literally.
You will obviously not be able to send emails from legit domains such as Paypal.com, Chase.com, and even Cloudflare.com. I tried and even I got 202 status code, but the email was not received. And I think this good, as this API is only meant for sending email notifications or important logs from your workers.
How to Send Emails using Cloudflare Workers from any Domain for Free?
You will obviously need a Cloudflare account to send emails from Workers. So, log in to your dashboard and then simply create a new worker. There is a test script on the Cloudflare announcement blog which you can use. Or, you can use the one that I tweaked a little from here. I have basically added an HTML form that takes recipient name and address along with emails message that needs to be sent.
So, delete all the default code in the editor and then paste the worker script code from above. Save the changes and then you can test it in the editor itself. If you are able to see the simple HTML form, then it means it is working.
Now, you enter some data in the form. Type the recipient name, email address, subject line, and then message. Hit the Send button and the check the inbox. If you get the status code “202” then it means your email has been sent. This way, you can send more emails, however spam emails will be blocked automatically.
For sending free emails, you can leverage this new feature of Cloudflare Workers. It is phenomenal and works as it supposed to. You can use a custom domain to send an email, but do not use domain of a popular entity, as it will be considered spam and you will get errors like 500 or 502.
Also see: Using Cloudflare Workers to Host Notion Pages as Website on Custom Domain
Final thoughts:
If you have a Cloudflare account, then you can now send emails from your Cloudflare Workers. Just use the simple example script that I have mentioned here, or you can also create your own if you have JavaScript knowledge. So, give this a try and let me know what you think about it. Personally, I think it is great, but at first I was a bit skeptical about the abuse of this service by spammers. But after trying it myself, I can safely say that its spam filters are powerful and it can be a great feature to send free notification or transactional emails from Cloudflare Workers.