Setting Up Custom Email with Cloudflare and Gmail
Published Article

Setting Up Custom Email with Cloudflare and Gmail

In-depth Article
9 min read

This documentation provides a step-by-step guide to configuring email reception and sending for a custom domain using Cloudflare Email Routing and Gmail. This setup allows you to receive emails sent to your custom domain (e.g.,

info@yourdomain.com
) in your Gmail inbox and send emails from that custom address via Gmail.

Prerequisites:

  • A registered domain name (e.g., via a registrar like GoDaddy or Namecheap).
  • A Gmail account (preferably a business one for professionalism).
  • Access to your domain registrar's DNS settings to update nameservers.
  • Two-factor authentication (2FA) enabled on your Google account (required for App Passwords).

Important Notes:

  • This setup is free for basic use with Cloudflare (up to 200 custom addresses) and Gmail.
  • Always verify changes in a test environment to avoid email disruptions.
  • If you encounter errors, check Cloudflare's status page or Gmail's help center.
  • For editing configurations later, refer to the "Editing and Managing Configurations" sections under each main topic.

1. Receiving Emails (Using Cloudflare Email Routing)

Cloudflare Email Routing forwards emails from your custom domain to your Gmail inbox without needing a full email hosting service. This is ideal for simple setups like contact forms or business inquiries.

Step-by-Step Setup

  1. Create a Cloudflare Account:

    • Go to cloudflare.com and sign up using your business Gmail address.
    • Verify your email by clicking the confirmation link sent to your Gmail inbox.
    • Complete the account setup by providing basic information (no payment required for this feature).
  2. Connect Your Domain and Update Nameservers:

    • In your Cloudflare dashboard, click "Add a Site" and enter your domain name (e.g.,
      yourdomain.com
      ).
    • Cloudflare will scan your existing DNS records. Review and confirm them.
    • Copy the provided Cloudflare nameservers (e.g.,
      ns1.cloudflare.com
      and
      ns2.cloudflare.com
      ).
    • Log in to your domain registrar (e.g., GoDaddy) and update the nameservers to point to Cloudflare's. This change may take 24-48 hours to propagate (use tools like
      whatsmydns.net
      to check).
    • Once propagated, return to Cloudflare and verify the domain is active.
  3. Navigate to Email Routing:

    • From the Cloudflare dashboard sidebar, select your domain.
    • Go to Email > Email Routing.
    • If prompted, enable Email Routing for your domain.
  4. Add Custom Email Addresses:

    • In the Email Routing section, click "Add Custom Address."
    • Enter your desired custom email (e.g.,
      info@yourdomain.com
      ). You can add up to 200 addresses.
    • Repeat for additional addresses if needed (e.g.,
      support@yourdomain.com
      ).
  5. Add Destination Email Address:

    • For each custom address, specify the destination (your Gmail address, e.g.,
      yourbusiness@gmail.com
      ).
    • Cloudflare will send a verification email to your Gmail. Check your inbox (including spam) and confirm the link.
  6. Confirm and View Dashboard:

    • Follow on-screen prompts to confirm each step.
    • Once set up, you'll see the Email Routing dashboard showing active routes, status, and metrics (e.g., emails forwarded).
  7. Enable Catch-All Routing:

    • In the Email Routing section, go to Routing Rules.
    • Enable the "Catch-all" rule. This forwards any email sent to undefined addresses on your domain (e.g.,
      random@yourdomain.com
      ) to your specified destination (Gmail).
    • Test by sending an email to a non-configured address on your domain; it should arrive in Gmail.

Testing Reception

  • Send a test email from another account to your custom address.
  • It should forward to your Gmail inbox within minutes.
  • If not, check Cloudflare's email logs in the dashboard for errors (e.g., DNS issues).

Editing and Managing Configurations

  • Edit Custom Addresses: In Email Routing, select an address and update the destination or delete it. Changes take effect immediately.
  • Add/Remove Destinations: You can route to multiple destinations (e.g., multiple Gmails) by adding them in the rules.
  • Disable Catch-All: Toggle it off in Routing Rules if you want strict address matching.
  • Monitor and Troubleshoot: Use the dashboard's audit logs to view forwarded emails. If propagation issues persist, flush DNS cache on your device (
    ipconfig /flushdns
    on Windows).
  • Delete Setup: If needed, remove the domain from Cloudflare and revert nameservers in your registrar.

2. Sending Emails (Using Gmail as SMTP Relay)

This configures Gmail to send emails from your custom domain, making your outgoing messages appear professional (e.g., from

info@yourdomain.com
instead of
yourbusiness@gmail.com
).

Step-by-Step Setup

  1. Create a Google App Password:

    • Go to myaccount.google.com and sign in.
    • Navigate to Security > Signing in to Google > App passwords (requires 2FA enabled).
    • Select "Mail" as the app and "Other" as the device; name it (e.g., "Custom Domain SMTP").
    • Generate and copy the 16-character password (it won't be shown again—store securely).
  2. Access Gmail Settings:

    • Open Gmail in a web browser.
    • Click the gear icon (> Settings) > See all settings.
  3. Add Another Email Address:

    • Go to the Accounts and Import tab.
    • Under "Send mail as," click Add another email address.
    • In the popup:
      • Enter a display name (e.g., "Your Business Name").
      • Enter your custom email address (e.g.,
        info@yourdomain.com
        ).
      • Uncheck "Treat as an alias" (this ensures replies go to the custom address, not your Gmail).
  4. Configure SMTP Settings:

    • Click "Next Step."
    • Set:
      • SMTP Server:
        smtp.gmail.com
      • Port:
        587
      • Username: Your Gmail address without
        @gmail.com
        (e.g.,
        yourbusiness
        ).
      • Password: Paste the App Password from Step 1.
      • Select "Secured connection using TLS (recommended)."
    • Click "Add Account."
  5. Verify the Setup:

    • Gmail will send a verification email to your custom address (which forwards to your Gmail inbox via the reception setup).
    • Open the verification email in your Gmail inbox.
    • Click the verification link (or copy the code if provided).
    • In the confirmation popup, click "Confirm."
    • Refresh your Gmail tab to apply changes.
  6. Send a Test Email:

    • Compose a new email in Gmail.
    • In the "From" dropdown, select your custom address.
    • Send to a test recipient and verify the sender appears as your custom email.

Editing and Managing Configurations

  • Edit Sender Details: In Gmail Settings > Accounts and Import > Send mail as, click "edit info" next to the custom address. Update name, SMTP details, or toggle alias treatment.
  • Regenerate App Password: If compromised, revoke the old one in Google Security and create a new one, then update in Gmail settings.
  • Remove Custom Address: In the same section, click "delete" next to the address. This won't affect reception.
  • Troubleshoot Sending: If emails fail, check for SMTP errors in Gmail (e.g., wrong port). Ensure your domain's SPF records include Gmail (add
    include:_spf.google.com
    in Cloudflare DNS).
  • Add Multiple Customs: Repeat the process for additional addresses (e.g.,
    support@yourdomain.com
    ).

Advanced Tips and Best Practices

  • Security: Use strong passwords and monitor for spam. Enable DMARC/DKIM in Cloudflare DNS for better deliverability (go to DNS > Add Record: TXT with
    _dmarc.yourdomain.com
    and value
    v=DMARC1; p=none
    ).
  • Limitations: Cloudflare routing is forward-only (no storage). For full email hosting, consider upgrading to paid services like Google Workspace.
  • Backup: Export Gmail settings periodically. Test setups monthly.
  • Compliance: Ensure this aligns with email laws (e.g., CAN-SPAM for marketing).
  • Alternatives: If Gmail limits are an issue (e.g., sending quotas), explore SMTP providers like SendGrid.

This setup provides a cost-effective, professional email solution. If you need customizations or troubleshooting, refer to official docs: Cloudflare Email Routing or Gmail Help.

Live Demo & Source

Explore the working implementation and examine the source code

View Live Demo

Enjoyed this article?

Share it with your network and help others discover valuable insights