The goal is to be able to receive and send emails from all the domains of your websites / side projects. As emails will most likely come in infrequently, it makes no sense to set up individual Google Suite or AWS WorkMail accounts as they come in at $4-6 per mailbox.
While forwarding email to one specific address is easy, you most likely also want to reply from the same same domain to whoever sent you an email. To achieve this, we will use a free gmail address/inbox which we forward all incoming email to via Mailgun and tag emails with a label. Lastly, we will add the option to send email in the name of the domain from your Gmail inbox as well. Most steps in this tutorial I learned from Xavi Esteve's excellent blog post about the same topic.
Two important things to note: This assumes you haven't already connected email functionality to your domain. Please be very careful as messing this up would mean you can't receive mail. Also, while Mailgun has as of this writing 10,000 free emails for you to receive/send per month, it does require a credit card. Once you venture beyond 10,000 monthly emails you should rethink your email strategy by the way.
This step is simple, just go to gmail.com and open another (?) free email account.
For this step, you need to create a Mailgun account and confirm your email address. Then, add a custom domain and set the DNS records in Cloudflare to receive (and send) email. Important — the default tutorial in Mailgun tells you to use a subdomain, if you do so, you will not be able to receive email correctly. So the DNS settings I use in Cloudflare are as follows:
Type | Name | Value | Cloudflare status |
Explanation |
---|---|---|---|---|
MX | @ | mxa.eu.mailgun.org | — | Direct email sent to "@yourdomain.com" to Mailgun |
MX | @ | mxb.eu.mailgun.org | — | Same as above, fallback |
TXT | smtp._domainkey | k=rsa; p=XXXXX.... | — | DKIM record |
TXT | @ | v=spf1 include:eu.mailgun.org ~all | — | SPF record |
CNAME | eu.mailgun.org | DNS only | To track email opens, clicks, and unsubscribes |
Quick note — since I'm based in the EU, I'm using Mailgun's EU setting. It may be different for you if not in the EU.
While the CNAME record to track email opens, clicks, and unsubscribes may not exactly be necessary, please note that I needed to select "DNS only" (grey arrow going around the cloud) instead of Cloudflare's "DNS and HTTP proxy (CDN)" setting (orange arrow going through the cloud) to get it properly recognized by Mailgun.
Before proceeding, make sure all icons are green in the Mailgun dashbord:
Congrats, the first step is down - Mailgun receives your email! The thing is though, it doesn't do anything with it yet. So the last step is to add a rule that forwards all incoming email to your Gmail inbox. Head over to your Mailgun dashboard, go to routes and click on "Create Route".
Select "Catch All", and add your gmail address from above into the "Forward" box and confirm at the bottom with "Create Route". You're done now with receiving email, all incoming email sent to any email address on your domain will be forwarded to your Gmail inbox! So go and test it by sending an email to "[email protected]" and see if it gets forwarded.
One more thing, I always turn the spam filter on right away. At the beginning probably not necessary, but I trust it and it reduces spam from the first email received. Just go to "Settings" and then turn the "Inbound Spam Filter" on:
As a last step to easily distinguish emails by the domain they were received from in Gmail, it is a good idea to assign tags. In Gmail, go to "Settings" and then "Filter and Blocked Addresses". Add a rule by filtering all email with to:
(!) matching *@YOURDOMAIN.COM
. As an action, apply the (newly created) label YOURDOMAIN.COM
. Voilà, all email that was sent to YOURDOMAIN.COM (and got to this inbox by being forwarded through Mailgun) will get the label assigned. So when you look at your Gmail inbox, you will easily spot which email comes from where.
In Gmail, go to "Settings", "Accounts and Import" and select "Add another email address you own". Add the email address you would like to send your emails from YOURDOMAIN.COM
, this can either be "[email protected]" or a generic address like "[email protected]".
On the next screen input the name you want to be shown for the emails you send. Lastly, you need to fill the smtp credentials—Gmail needs to know how to send money from YOURDOMAIN.COM
through Mailgun. You can find all information in the Mailgun dashboard by going to "Settings", "SMTP credentials". Then go to "New SMTP User", add the exact email address you specified in Gmail to send, and copy the password. Together with the SMTP settings on the right hand side you have all info for the Gmail.
When you now start a new email in Gmail you can choose the sender!