Home

Aaron Tan's Blog

14 Apr 2018

Setting up email on a domain with Cloudflare

So one of my coworkers, Justin, has a nice email on his domain. So I thought that I would try and imitate him. Can’t be that hard, I thought. I just want to have an email like [email protected], so I can be one of those cool kids.

And it really isn’t, although having Cloudflare throws a wrench in what would otherwise be a simple process. I’m leaving this up sort of as documentation for myself, but also in case anybody else wants to do this!


An email on a custom domain

This is a family recipe, passed on for at least one generation. You’ll be sure to love the feeling after using, just like a vanity URL!

Ingredients:

  • One custom domain (e.g. aaronhktan.com)
  • One Cloudflare account
  • One Mailgun account
  • One credit card (don’t worry, it won’t be charged)
  1. Create a Mailgun account. Prepare your credit card number. You won’t be charged unless you send/receive more than 10,000 emails in a month with this account, which you really shouldn’t be doing. Otherwise, what are you doing on this website?

  2. Add your website’s domain name in Mailgun, without the http:// or www. In my case, it was aaronhktan.com.

  3. In a separate tab, open Cloudflare, and select DNS settings. You might have some MX records that look like eforward1.registrar-servers.com and TXT records that look like v=spf1 include:spf.efwd.registrar-servers.com ~all. Delete them.

  4. In your Cloudflare DNS settings, add a CNAME record by selecting CNAME in the dropdown, with “Name” email and “Click to configure” mailgun.org. Make sure this cloud is grey, and not orange; that means it’s DNS only, with no HTTP proxy! You can change it by clicking on the cloud.

  5. Check back on at Mailgun. You should see two TXT records that it instructs you to add. Add these into Cloudflare by selecting “TXT” in the dropdown. The Hostname in Mailgun corresponds to “Text” in Cloudflare, and the Enter this value from Mailgun is the content you should put into “Click to configure” in Cloudflare.

  6. In Mailgun, you should also see two MX records to add. In Cloudflare, select MX in the dropdown, then fill according to the following: “Name” in Cloudflare should be your domain (in my case, aaronhktan.com), and “Click to configure” should be mxa.mailgun.org for the first MX record, then mxb.mailgun.org for the second.

  7. Now that your Cloudflare is ready, it’s time to check back again at Mailgun. Click “Add”, then scroll down and “Check DNS records now”. You should see that verification was successful if you set up Cloudflare correctly.

  8. In the upper menu bar of Mailgun, there’s a tab called “Routes”. Click it. Create your first route, then Match Recipient and enter the email you want to receive email at in the Recipient field (in my case, [email protected]). After that, check the Forward checkbox, and enter the email where you want to receive the email in. For me, I have it forward to my Gmail account.

  9. Name it something interesting, and save. Set Mailgun aside for now.

  10. Go to Gmail, and open Settings. Under accounts and import, click Add another email address. In the pop-up that opens, use the email that you set up in Mailgun (in my case, [email protected]). Leave “Treat as an alias” checked.

  11. Check back at Mailgun. Under “Domains” > “Domain Information”, there should be a SMTP Hostname, Default SMTP Login, and Default Password. Put these in the Gmail pop-up fields SMTP Server, Username, and Password respectively. Leave “Secured connection using TLS” checked.

  12. Click “Add account” and you should be good! Google will send an email to your new email, where you click a link to verify. For me, they sent me an email to [email protected], and that got forwarded to the email because of the mails I had in place in Mailgun.

  13. Bon appétit!


On a separate note, you can email me at [email protected] now. Come say hi!

aaron at 16:57

footer