Host your own email domain with Exim4

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).


  • 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 “” pointing to “” (replace “” to your actual domain, without “www”)

My MX record

PS: after that, you can test your MX record with this tool:
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:

sudo apt-get install exim4 exim4-base exim4-config exim4-daemon-heavy

3. recreate the configuration files:

  • on the interfaces its required to leave empty
  • split files?: you need to answer YES!!!
sudo dpkg-reconfigure exim4-config

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

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

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

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

sudo rm /etc/exim4/exim4.conf

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

sudo update-exim4.conf

7. create a folder called /etc/valias:

sudo mkdir /etc/valias

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

sudo nano /etc/valiases/
bob: [email protected]
pam: [email protected]
info: [email protected], [email protected]
*: [email protected], [email protected]

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

#domainlist local_domains = MAIN_LOCAL_DOMAINS
domainlist local_domains = @:localhost:dsearch;/var/mail/virtual:dsearch;/etc/valiases

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

      driver = redirect
      domains = dsearch;/etc/valiases
      data = ${expand:${lookup{$local_part}lsearch*@{/etc/valiases/$domain}}}
      pipe_transport   = address_pipe
      file_transport   = address_file

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

12. restart exim4 service

sudo /etc/init.d/exim4 restart

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 SSL cert for free:

Close Menu