DEV Community

Cover image for How to Send Emails Using Gmail SMTP with Cloudflare Email Routing?

How to Send Emails Using Gmail SMTP with Cloudflare Email Routing?

Pierre-Henry Soria ✨ on August 20, 2024

In this dev post, I will describe the steps you can use for sending emails through Gmail SMTP with Cloudflare Email Routing. There are various rea...
Collapse
 
miqla profile image
Miquel MM • Edited

Pierre, many thanks to share it so this is what I needed.

Just one question, do you know how to skip spam to be marked in these emails sent by this way?

Everything is working, but all emails are going to spam, any suggestion? Or is it normal because the email account has been configured recently on both sides, Cloudflare and Gmail?

Thanks in advance.

Collapse
 
groom profile image
Gorm Kjeldsen

Hi Miquel

Did you figure this out? I'm looking into doing this, and it would suck to have all my outgoing mail marked as spam. :(

Collapse
 
miqla profile image
Miquel MM

Hi Gorm,

Yes, I figured it out. The first thing to keep in mind is that it requires some patience to avoid having your emails marked as spam. It usually takes a few days, around a week, after everything is properly configured—especially the DNS records on Cloudflare.

Since the email account is new, Google needs some time to evaluate the configuration before deciding whether your emails should be marked as spam or not.

I recommend double-checking all your settings, particularly ensuring that your SPF record includes Google (I realized I had multiple SPF records, but I missed including _spf.google.com).

Additionally, I tried manually marking emails as "Not Spam" in other email accounts where I received test messages that were initially marked as spam. This helped Google learn that the emails were legitimate, and after a few days, it definitely worked.

Hope this helps!

Thread Thread
 
groom profile image
Gorm Kjeldsen

Thank you so much for your reply. This gives me more confidence in this solution, and I'll probably go with this then. Great info! :)

Collapse
 
alansv22 profile image
Alan S

Hi - this article has helped me a lot, thank you.

All working but I have a couple of questions:

I'm getting "unable to verify sender" alerts when e-mail messages (sent via Gmail smtp) are seen in the recipient's mailbox (this is MS365/Outlook) so is there any extra DNS config that needs to be added to fix this?

Also - is the SPF record for Gmail smtp: "_spf.google.com" correct? This is mentioned in Google Support for Google Workspace but wondered if personal Gmail (i.e. non business/workspace is also covered by this) or should it be "_spf.gmail.com"? I hope that makes sense - thanks!

Collapse
 
pierre profile image
Pierre-Henry Soria ✨ • Edited

You should have received an email from Gmail Team gmail-noreply@google.com. And the email subject should be Gmail Confirmation - Send Mail as <YOUR_CUSTOM_EMAIL_ADDRESS>

Have a look in your spam folder (very likely to be in there 🙂).
Hope it helps!

Collapse
 
idolize profile image
David Idol

For the last step (DMARC) which email address are we putting in? The gmail one or the custom domain one?

Collapse
 
pierre profile image
Pierre-Henry Soria ✨

Your custom email address you have added in Cloudflare. Not the gmail one.

Collapse
 
alejandropixel profile image
Alejandro

Thanks for the post! It really helped me get my email set up.

What advantages/disadvantages does this method have compared to a traditional email hosting account?

Thanks in advance.

Collapse
 
pierre profile image
Pierre-Henry Soria ✨ • Edited

Great question! Cloudflare offers many great features, extra security layers, DMARC Management, the "catch-all address" (can be super handy), clear email logs from Cloudflare Email (to check if an email was forwarded to our gmail or not), etc.

Collapse
 
peter_geissler_4c524b01cc profile image
Peter Geissler

How do I set this up so I am sending from my cloudflare email address? In your examples you are using a different gmail address.