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!
- One custom domain (e.g. aaronhktan.com)
- One Cloudflare account
- One Mailgun account
- One credit card (don’t worry, it won’t be charged)
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?
Add your website’s domain name in Mailgun, without the
www. In my case, it was
In a separate tab, open Cloudflare, and select DNS settings. You might have some MX records that look like
eforward1.registrar-servers.comand TXT records that look like
v=spf1 include:spf.efwd.registrar-servers.com ~all. Delete them.
In your Cloudflare DNS settings, add a CNAME record by selecting CNAME in the dropdown, with “Name”
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.
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
Hostnamein Mailgun corresponds to “Text” in Cloudflare, and the
Enter this valuefrom Mailgun is the content you should put into “Click to configure” in Cloudflare.
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.orgfor the first MX record, then
mxb.mailgun.orgfor the second.
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.
In the upper menu bar of Mailgun, there’s a tab called “Routes”. Click it.
Create your first route, then
Match Recipientand enter the email you want to receive email at in the
Recipientfield (in my case, [email protected]). After that, check the
Forwardcheckbox, and enter the email where you want to receive the email in. For me, I have it forward to my Gmail account.
Name it something interesting, and save. Set Mailgun aside for now.
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.
Check back at Mailgun. Under “Domains” > “Domain Information”, there should be a
Default SMTP Login, and
Default Password. Put these in the Gmail pop-up fields
Passwordrespectively. Leave “Secured connection using TLS” checked.
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.
On a separate note, you can email me at [email protected] now. Come say hi!
aaron at 16:57