I will show here how to host your own email domain (or domains) for free! Yeah, you can have your own [email protected] instead of [email protected], which is much more professional, and for free.

But calm down. This it’s a very simple solution that relays on redirection, using a free gmail account (or your prefered email host) behind the scenes. Yeah, it’s a poor man’s email solution, but your service will have a profissional look, very similar that if you had choose to buy a Google Apps for Enterprise account. Your customers will never know that you are using gmail (or whatever provider).

WARNING: This tutorial won’t show how to do a full POP3/SMTP. It’s only a MTA server with redirection. But hell yeah, its a good enough solution for small sites.

WARNING II: if you want to host your own email domain because you are afraid of NSA or something like that, I recommend to you a psychiatristI recommend stop to selling drugs, this won’t be a good solution because it uses gmail as a smtp/pop3 server. But the procedures to have a full email server are pretty similar to this, only a bit more complicated (you will have to install postfix and courier too).

Ingredients:

  • shell access to the server (I’m using Ubuntu 14.10 here)
  • registered domain with access to manage MX records (I’m using CloudFlare as a free DNS management provider)
  • generic email account (eg. [email protected])

Our recipe:

0. in our example we’ll have 3 emails:

1. create your DNS records:

  • create an A record called “mail” record pointing to your server IP
  • create a MX record called “example.com” pointing to “mail.example.com” (replace “example.com” to your actual domain, without “www”)

My MX record

PS: after that, you can test your MX record with this tool: http://mxtoolbox.com/SuperTool.aspx
PS II: In MX Toolbox, click on “SMTP Test” should be generate an error since we don’t configurate Exim4 yet. But at the end of this tutorial, “SMTP Test” should work.

2. install Exim4:

3. recreate the configuration files:

  • on the interfaces its required to leave empty
  • split files?: you need to answer YES!!!

4. nano /etc/exim4/update-exim4.conf.conf:

  • Change example.com and example2.com to your actual domains
  • If you have just 1 domain, use something like: dc_other_hostnames=’example.com’

PS: actually “dc_other_hostnames” are optional. You can leave this blank or even incomplete.

5. remove the overrider configuration file, if it exists:

6. recreate the auto-generated config file (/var/lib/exim4/config.autogenerated):

7. create a folder called /etc/valias:

8. create one configuration file for each domain at /etc/valiases:

PS: Note the * at the last line. It’s optional and means that any email that doesn’t match with the above rules will be match here. In this case, [email protected] will be sended to bob and pam.

9. nano /etc/exim4/conf.d/main/01_exim4-config_listmacrosdefs

10. nano /etc/exim4/conf.d/router/350_exim4-config_vdom_aliases

11. add your domains to /etc/hosts (OPTIONAL – its just for speed sake)

12. restart exim4 service

13. test if its all working:

14. TLS (optional):
if you want to enable TLS (although isn’t required), you can use this tutorial and a CAcert.org SSL cert for free: https://github.com/Exim/exim/wiki/EximServerSslCertificate