Using a Custom Domain in Gmail for Free with Mailgun and Sendgrid

Update on 26 November 2018: @niftylettuce recently launched a new service called forwardemail.net which does the same thing as described below (forwards email to Gmail and sends email from Gmail via a custom domain) with just a few small DNS records. It’s free, and if you want to host your own instance, it’s open source too. If you’re looking for a free and easy-to-use custom email solution, I would highly suggest you take a look!

If you love Gmail’s interface and also love your custom domain, but don’t love them both enough to pay $5/user/month for the G Suite, don’t worry: there’s a way to get the best of both worlds for free!

Free smoke, free smoke aye!

Prior Art

Ian Macalinao’s “Hacking Gmail to use custom domains for free” (2015) has been my go-to guide for setting up custom domains in Gmail for the past few years. Essentially, he uses Mailgun’s routes to forward email to his Gmail account and hooks into Mailgun’s SMTP servers to send email.

Recently, Issa Caption needed an email platform that could integrate with Gmail for easy sending and receiving from @issacaption.com email addresses. Familiar with Ian’s method, I decided to use Mailgun.

I created the account, and Mailgun’s routes continued to work great. Email was being forwarded to my Gmail almost instantaneously.

Unfortunately, between the time of Ian’s article and today, I learned that Mailgun instituted a new policy for free accounts which prevents emails from being sent to recipients that aren’t authorized. Essentially, free users have to send an email to potential recipients asking them whether they’re OK with receiving email before any of their messages will get through — previously, free users could send messages to anyone without restriction. This pretty much rendered moot the benefits of sending with a custom domain through Mailgun, so I had to find a different solution.

Julian Scarfe noted that if you give Mailgun your credit card number, you can still use the plan that Ian used — you’ll just get an invoice every month for $0. If you are alright with giving Mailgun your credit card number, go ahead and try Ian’s method!

Here’s how I got Issa Caption’s email working again.

What we’re going for: sending from nate@issacaption.com and receiving at yo@issacaption.com, all in Gmail

Part 1: Receiving Emails to @issacaption.com

When I learned about Mailgun’s send restrictions, I initially considered moving all of my email to another transactional email provider — namely, Sendgrid, which I had familiarity with from the Github Student Developer Pack. Regardless, I couldn’t find anything on Sendgrid which could had the same flexibility as Mailgun’s routes — the closest Sendgrid service I could find was their Inbound Email Parse Webhook, which would require another server to actually receive the contents of the email (i.e. I couldn’t just forward the email to Gmail).

As a result, I ended up keeping Mailgun on the receiving end.

Step 1

Sign up for Mailgun using an email address you have access to — like your Gmail address. You need access because you’ll need to confirm your email address in order to get your account set up.

Step 2

Once you’re signed up and on the Mailgun dashboard, click “Domains” in the upper left, and then click the dark gray “Add Domain” button.

Step 3

On the “Add Domain” screen, Mailgun will recommend using a subdomain (e.g. mail.issacaption.com), but that’s mainly for sending purposes. It has to do with domain reputation: if you accidentally send a whole bunch of spammy emails from your root domain (e.g. issacaption.com), the domain will be flagged by other mailservers and your root domain’s reputation will be pretty much ruined forever.

We’re not using Mailgun for sending, though — only for receiving — so put your main domain in there (in my case, issacaption.com). A subdomain won’t work if you want to receive to an email address on your root domain.

Don’t listen to them, they’re wrong

Step 4

Mailgun will give you a whole bunch of DNS records to set up in order to verify your domain and enable sending and receiving capabilities. You’ll need to set all of them (if you don’t know how to set DNS records, check out this article from wpbeginner).

If you know DNS, you’ll that know that technically, only the MX records need to be set, but Mailgun won’t even forward emails until everything is set .

Here’s an example DNS configuration (issacaption.com uses Netlify DNS).

The TXT record on the bottom may look a little different from yours because I’m also using MailChimp.

Step 5

Once your domain is verified, you can configure the key part: forwarding to your Gmail address. Hit “Routes” in the middle-top of the Mailgun dashboard, and then click the “Create Route” button once you’re on the page.

Blotted out the personal email addresses, but this is what Issa Caption’s routes page looks like.

Step 6

On the “Create New Route” page, choose “Match Recipient” for Expression Type, type in your desired custom-domain email address into the Recipient field, and check the “Forward” box.

After that, you can simply scroll down, add a description (like “Kanye’s email”) and click “Create Route”.

Kanye’s emails go through the wires

Step 7

At this point, we’re done! It may take a little while for the routes to kick in, but in my experience it’s been pretty quick — I like to use IsMyEmailWorking.com to test afterwards.

Part 2: Sending Emails from @issacaption.com

The problem with using Mailgun for sending was that anyone who I wanted to send a message to would have to click “I Agree” on a message looking like this beforehand. I didn’t want to have to deal with that, so I decided to use SendGrid instead.

I Agree!

Step 1

Sign up for SendGrid. They make it a bit tough to find the free plan — you’ll have to first hit the “Sign Up” link in the upper right, and then you have to scroll about halfway down the page until you see the button that says “Try for Free”. Click that and you should be able to sign up on a Free Trial.

Also, now that you can receive emails, feel free to sign up for the account using your new custom email address! (Make sure you test it first at IsMyEmailWorking.com, though).

Free emails, love that!

Step 2

Once you sign up, you’ll need to create an API key. To access the API Keys dashboard, navigate to the “Settings” panel on the left side and click the small downward-facing chevron. The third link down should read “API Keys” — click that.

The SendGrid dashboard

Step 3

To create an API key, hit the “Create API Key” button in the top right of the SendGrid dashboard. In the modal that opens, create an API key with “Full Access.” You can name it whatever you want — you only need one.

After you click “Create & View,” your API key will be displayed. However, after closing the modal you won’t be able to see it again, so copy it into another document or write it down somewhere so you don’t lose it.

Step 4

We can now set up Gmail. I usually use Inbox, but Gmail’s settings are easier to find, so if you’re an Inbox user, make sure you visit real Gmail. (If you’ve got the Gmail → Inbox redirect set up, check out this Google Support article to turn it off).

Once you’re in Gmail, click the gear icon in the top right and click “Settings.” On the Settings screen, click the “Accounts and Import” tab, fourth from right.

Here’s what Issa Caption’s settings screen looks like.

Step 5

In the “Send mail as:” section, click the “Add another email address” link. Enter your desired sender name and custom sending address into the corresponding fields, and make sure you have access to your desired custom email — Gmail will send a confirmation to the custom email address to make sure it’s OK that they’re sending emails under that name.

Also, make sure to uncheck “Treat as an alias.” Essentially, unchecking this box treats the other email address as a separate email address. It’s useful if you want to keep business and personal communications separate, and it ensures that when you reply, your custom domain shows up in the “From” field. This Google Support article gives more details.

Step 6

Next, type in these details into their corresponding fields.

SMTP Server: smtp.sendgrid.net
Username: apikey
Password: <your api key from step 3>

If you’re curious about where these credentials came from, SendGrid doesn’t seem to have official documentation on sending email through their SMTP server. The above information comes from this SendGrid API Reference article about sending an SMTP email via telnet.

Step 7

Gmail will first make sure that the SMTP credentials work. If they don’t, you may need to generate another API key , and if you end up doing that, make sure to disable the old one.

If the credentials do work, Gmail will send a confirmation email to your custom email address — which, if Mailgun was configured correctly, will land in your Gmail inbox! Simply click the link in the email, and when you go back to Gmail you should see an option to send mail from your custom email address when you’re composing your next message.

Limitations

Mailgun has a limit of 10,000 emails per month (which would be your receiving limit), and Sendgrid has a limit of 40,000 emails per month for the first 30 days and 100 emails per day afterwards (which would be your sending limit).

For general email, that’s a pretty good amount, and the combination of these two services is a great free solution for those looking to send email from a custom domain without having to purchase an enterprise solution like G Suite.

For bootstrapped startups (like Issa Caption!), 10K in/3K out may not be sufficient for all marketing email — in that case, there’s tons of other awesome email marketing platforms that have generous free plans. In my case, in addition to Mailgun and SendGrid, I’m also using MailChimp, which has a limit of 2K subscribers and 12K emails per month.

Anyway, happy emailing! If you have any questions, feel free to reach out at nate@issacaption.com or leave a comment below.


Issa Caption finds the perfect caption for your Instagram posts using cutting-edge technology. We’re launching soon! Sign up on our website to be notified for the beta.