Setting Up Mailgun With CloudFlare

3 minute read


After signing up for CloudFlare to host my website, I found that it will automatically disable Google’s free email address that comes with the domain. I used the following steps to resolve this:

To Resolve:

  1. Signup for a free account on

  2. Log into your account in Mailgun and add a domain from the top menu bar. Once your domain is added, you will see that Mailgun gives you a few MX records and TXT records to be added for your domain, for both successful email forwarding and verification of the domain.

  3. Now go to CloudFlare’s DNS panel and add those MX records and TXT records provided by Mailgun.

    • Choose your site and select DNS Settings

    • Add the CNAME record. Name = email, Value =, TTL = Automatic, Make sure the cloudflare cloud is gray and not orange/active => You have to click on the cloud icon.

    • Add the two MX records
      • Name = (no www), value =, Priority = 10
      • Name = (no www), value = Priority = 10
    • Add the two TXT records
      • Name= (no www), value = v=spf1…
      • Name = smtp._domainkey, value = k=rsa…
  4. Log into your Mailgun account and go to Routes section from the top menu. Now add as many routes as you want.

    • For example, if your domain is and you want all the mails sent to to be forwarded to then create that route. So for me that means:

      • Expression Type = Match Recipient
      • Recipient =
      • Actions = Forward to
      • Priority = 10
      • Description = Forwards from my domain to my Gmail.
  5. If you want people to email TO you at that email, you are done, congrats. I wanted to go one step further and send email FROM that email address. To do this, I went into my Gmail and:
    • Log in to Gmail and go to settings => Accounts and Import:
      • name = Anything you want
      • email address: (this should be the email you set up in the steps before)
      • Leave treat as an alias checked
      • Click Next Step
  6. 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
    • I couldn’t get this to work, so I created a new SMTP user and password. I plugged this into Google. So it was:
    • SMTP Server: PORT=587
    • Username: MyUserEmail
    • Password: MyUserPassword
    • Secured connection using TLS (recommended) radio button selected
    • Now comes the hard part, Gmail will send an email to that address and you will have to open to go to the link for verification:
    • Thankfully, Mailgun is aware of people needing temp access to their mailboxes, so they created an event API that works like this:
    • You login to Mailgun and go to Logs for your domain and select the most recent inbox message.
    • You can see the API URL to the message along with its unique key under the “storage” section when expanding the log entry.
    • To view the message in the browser just copy the URL and enter api as username and your API key in the password box. This will let you to view the parsed message. You get your API key under Account Settings in the web GUI.
    • Copy and paste the Google verification link in another tab to “authorize” your email as a trusted sender.
  7. Now you can send and receive from a mailbox that seems to be connected to your domain!


“How-To: Set up Email Forwarding for your domain using Mailgun”