Forwarding Email to Gmail with Digital Ocean and Ubuntu
For my new website, I’m using Digital Ocean as a host. Since my DNS is going through them and not NameCheap (my registrar), I needed to figure out how to forward any email that came to @goodandlost.com to my own personal email account. It turns out there isn’t much documentation on it, and Digital Ocean, the creators of some of the best technical documentation available on the Internet, even wrote a guide trying to convince us not to try to do this. Uhhh.
Who needs them anyway? Start by adding the appropriate DNS records. You need two of them:
- An A record with the name
- An MX record with a priority (I used 1, it doesn’t matter) and
mail.yourdomainname.com.Note the period at the end!
Here’s what mine look like:
Now we need an MTA, so let’s install Postfix.
It’ll ask you to input your domain name. Enter the full domain name with no subdomain, for example,
Next we need to edit the Postfix config. The values you need to pay attention to here are myhysthome, virtual_alias_maps, virtual_alias_domains, and inet_protocols. My entire config is below for reference.
After that, we want to map some aliases to our Gmail (or whatever) accounts.
Or, if you want to make a catch-all for any email that’s sent to your domain:
Next, reload Postfix:
And that’s it! You should be good to go. Send a message from a different account (for whatever reason, Gmail wouldn’t deliver my messages from the same account) and see if it arrives in your inbox. If it’s not arriving, try tailing the Postfix error log while you send an email:
I hope that helps!