Skip to content
Learn Security

Gmail SMTP with Cloudflare Email Routing

Optimize your email infrastructure by integrating Gmail SMTP with Cloudflare's email routing capabilities. Enhance email delivery reliability and security while leveraging Cloudflare's robust network infrastructure. This configuration ensures efficient email handling and protection against potential threats, contributing to a more resilient email ecosystem.

5 min read
SMTP with Cloudflare

Integrating Gmail SMTP with Cloudflare Email Routing: A Comprehensive Guide

Want a secure and efficient email setup? Combining Gmail SMTP with Cloudflare Email Routing ensures robust email handling, enhanced deliverability, and protection against email spoofing. This guide provides a detailed walkthrough to help you set up and optimize your email infrastructure.


🚀 Step 1: Enable Two-Factor Authentication (2FA)

For security, Gmail requires 2FA to generate App Passwords. Follow these steps:

  1. Go to Google Account Security.
  2. Under Signing in to Google, click 2-Step Verification.
  3. Follow the prompts to enable 2FA.

Why? 2FA protects your account by requiring both your password and a unique code during login.


🔑 Step 2: Generate an App Password for SMTP

App Passwords allow third-party tools (like Gmail SMTP) to access your account securely.

  1. Visit Google App Passwords.
  2. Under “Select app,” choose Mail.
  3. Under “Select device,” choose your device (e.g., Windows Computer).
  4. Click Generate and copy the 16-character password.
StepActionOutcome
1Open App Passwords pageAccess Google’s secure credential setup.
2Select “Mail” and your deviceGenerate SMTP credentials.
3Copy the passwordUse it in Gmail SMTP configuration.

Note: Keep this password secure—it replaces your regular password for SMTP purposes.


✉️ Step 3: Add Cloudflare Email to Gmail

Next, configure Gmail to send emails using your Cloudflare-routed email address.

  1. Open Gmail and go to SettingsAccounts and Import.
  2. Under Send mail as, click Add another email address.
  3. Enter:
    • Your name.
    • Your Cloudflare-routed email address.
    • Untick “Treat as alias.”
  4. Click Next Step.

🛠️ Step 4: Configure Gmail SMTP Settings

Fill in the SMTP settings as follows:

  • SMTP Server: smtp.gmail.com
  • Port: 587
  • Username: Your Gmail address (e.g., yourname@gmail.com).
  • Password: The App Password from Step 2.
  • TLS Encryption: Enabled.

After saving, Gmail will send a verification email to your Cloudflare address. Confirm ownership by entering the code or clicking the provided link.


🔒 Step 5: Configure SPF and DMARC Records in Cloudflare

Proper DNS configuration ensures that your emails are authenticated and not flagged as spam.

✅ SPF Record

Add the following TXT record in your Cloudflare DNS settings:

TypeNameContentTTL
TXT@v=spf1 include:_spf.mx.cloudflare.net include:_spf.google.com ~allAuto

📊 DMARC Policy

To monitor and enforce email authentication, configure DMARC as follows:

TypeNameContentTTL
TXT_dmarcv=DMARC1; p=none; rua=mailto:your-email@example.comAuto

Tip: Replace your-email@example.com with an address where you’d like DMARC reports sent.


🌟 Benefits of This Setup

  • Improved Deliverability: Emails sent via Gmail SMTP are less likely to be flagged as spam.
  • Enhanced Security: SPF and DMARC reduce phishing risks.
  • Centralized Management: Gmail’s interface lets you manage Cloudflare-routed emails seamlessly.

“Integrating Cloudflare Email Routing with Gmail SMTP combines the best of email security and usability.” — Email Infrastructure Expert


🖼️ Visual Overview

Below is a simplified flow of how Gmail SMTP and Cloudflare Email Routing interact. This diagram visually explains the flow of email processing:

Visual Overview

Key Steps in the Process:

  1. Incoming Emails: Emails sent to your custom domain are first routed to Cloudflare based on your DNS records.
  2. Cloudflare Routing: Cloudflare forwards the emails to Gmail for processing.
  3. Outgoing Emails: Gmail’s SMTP server processes outgoing messages, ensuring they are authenticated and securely sent.
  4. Delivery: The emails are delivered to the recipient’s inbox after passing SPF, DKIM, and DMARC checks.

Why This Matters:

  • Enhanced Security: Cloudflare ensures that incoming emails are securely routed, protecting your domain from spoofing and phishing.
  • Reliable Delivery: Gmail’s robust SMTP server ensures your emails reach their intended recipients without being flagged as spam.
  • Centralized Management: Manage both incoming and outgoing emails seamlessly through a single Gmail interface.

Tools for Verification:

To ensure your setup works perfectly, use the following tools:

  • MXToolbox: Check SPF, DKIM, and DMARC records for proper configuration.
  • Mail Tester: Test your email’s spam score and general setup.
  • Google Postmaster Tools: Monitor sender reputation and resolve deliverability issues.

Pro Tip: Regularly review your DNS records and email policies to maintain optimal deliverability and security.

🎯 FAQ

1. What happens if I skip SPF or DMARC?

Without SPF or DMARC records, your emails might fail authentication checks, causing them to:

  • Land in the recipient’s spam folder.
  • Be outright rejected by strict mail servers.
  • Increase your domain’s risk of being spoofed.

Solution: Always configure SPF and DMARC records for secure email delivery.


2. Can I use another SMTP server?

Yes, you can use alternative SMTP servers such as those from Zoho, Outlook, or custom mail providers. However:

  • Gmail SMTP is recommended for its reliability, simplicity, and compatibility with Cloudflare Email Routing.
  • Ensure your chosen SMTP server supports the required encryption protocols (TLS/SSL).

3. What if I don’t enable 2FA?

2FA (Two-Factor Authentication) is mandatory for generating App Passwords in Gmail. Without it:

  • You cannot securely integrate Gmail with external tools like SMTP.
  • Your account may be more vulnerable to unauthorized access.

Recommendation: Set up 2FA to protect your Google account and unlock App Password features.


4. How can I verify that my SPF and DMARC records are working?

You can use online tools like MXToolbox SPF Validator or DMARC Analyzer to verify your records. Look for:

  • Proper syntax in SPF and DMARC records.
  • Successful authentication results in test emails.

5. What if my emails are still landing in spam?

Even with proper SPF, DKIM, and DMARC, emails may land in spam due to:

  • High bounce rates from previous campaigns.
  • Suspicious content or keywords in your email body.
  • Missing DKIM (DomainKeys Identified Mail) signatures.

Action Steps:

  1. Review email content for potential spam triggers.
  2. Add DKIM records to your DNS.
  3. Use tools like Mail Tester to analyze your email’s spam score.

6. Can I use this setup for business domains?

Yes! This setup works seamlessly for custom domains routed via Cloudflare. Just ensure:

  • You’ve set up proper MX records in Cloudflare for inbound emails.
  • Your SPF and DMARC policies reflect the domain’s requirements.

Pro Tip: If using a business domain, also set up DKIM for added security.


7. Are there any costs involved?

Both Cloudflare Email Routing and Gmail SMTP are free to use under their respective plans:

  • Cloudflare Email Routing: Free for basic email routing.
  • Gmail SMTP: Free for Gmail users under personal accounts (limits apply).

Note: Business domains or enterprise usage might incur additional costs.


For additional questions, feel free to explore:


Share article

Subscribe to my newsletter

Receive my case study and the latest articles on my WhatsApp Channel.