Skip to content

Instantly share code, notes, and snippets.

@typpo
Created February 6, 2017 06:14
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save typpo/e9cf762c08054dd73229fcc1c438f232 to your computer and use it in GitHub Desktop.
Save typpo/e9cf762c08054dd73229fcc1c438f232 to your computer and use it in GitHub Desktop.
Mail Forwarding With Mailgun and CloudFlare

Source

Mail Forwarding With Mailgun and CloudFlare

After moving my DNS from Namecheap to CloudFlare I lost the ability to use Namecheap as a mail forwarder. For anyone not sure what that is, essentially it allows you to receive email at anyname@your-domain.com and have it automatically forwarded somewhere else (like your personal Gmail account).

So, what I did is leverage a free account with Mailgun to setup the same thing.

Mailgun Setup

  • Create a Mailgun account
  • Add your domain name (no www)
    domain.com
  • Keep the page open and open a new tab to CloudFlare

Cloudflare

  • Choose your site and select DNS Settings
  • Add the two Text records
  • Add the CNAME record
    • Make sure the cloudflare cloud is gray and not orange/active
  • Add the two MX records
    • Name domain.com (no www)
    • Mail handled by mxa.mailgun.org or mxb.mailgun.org

Back at Mailgun

  • Click add
    • Click Check DNS Records Now
  • It'll tell you once it detects the updated DNS records

Email Forwarding

  • From Mailgun, choose Routes
  • Create Your First Route
  • Priority 10
  • Filter Expression This is where you list the email address you want to forward to gmail
    match_recipient("you@domain.com")
  • Actions This is the gmail address you want to receive your mail
    forward("me@gmail.com")
  • Description Name it something so you remember what it's for

Use Gmail to send mail from your domain

  • Log in to Gmail and go to settings
  • Go to Accounts and Import
  • Go to Send mail as and select add another email you own
    • name: Anything you want
    • email address: name@domain.com (this should be the email you set up in the steps before)
    • Leave treat as an alias checked
    • Click Next Step
    • For the following info you'll need to login to mailgun and use the info under Domain Information
    • SMTP Server Use SMTP Hostname from Mailgun
    • Username Use Default SMTP Login from Mailgun
    • Password Use Default Password from Mailgun
    • Leave Secured connection using TLS selected
    • Click add account
  • Once it's verified you should be able to compose emails and list your new email in the from line so nobody needs to know it's coming from your personal gmail account.
@MrMadClown
Copy link

Hey @typpo,
this seems outdated since Routing is not a free Mailgun Feature (anymore?)
Did you by chance find another way to accomplish this?

@typpo
Copy link
Author

typpo commented May 25, 2021

Lately I've been using https://improvmx.com/ for this

@Triloworld
Copy link

Triloworld commented Nov 29, 2022

Cloudflare Free have routing and is great one more feature :) I recommend
https://www.cloudflare.com/products/email-routing/
https://developers.cloudflare.com/email-routing/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment