I will show 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 more professional, and for free.
But calm down. This is a complex solution based on email redirection, using a free Gmail account behind the scenes. Yeah, it's a poor man's solution, but your email address will look professional. Your customers will never know that you are using Gmail (or whatever provider) behind the scenes.
WARNING
This tutorial doesn't show how to implement a full POP3/SMTP service. It's only an MTA server with redirection. But it's a good enough solution for small sites.
WARNING
If you want to host your own email domain because you are afraid of NSA or something like that, I recommend to you a psychiatrist I recommend stop selling drugs, this won't be a good solution because it uses Gmail as an SMTP/POP3 server, which means they will have access to your emails. But the process to implement a full email server is pretty similar to this, only a bit more complicated (you will have to install postfix
and courier
too).
[email protected]
);[email protected]
;[email protected]
;[email protected]
+ [email protected]
;A
record named mail
pointing to your server IP;MX
record named example.com
pointing to mail.example.com
(replace example.com
with your actual domain, without www
)Example on CloudFlare interface:
TIP
After that, you can test your MX record with this tool: https://mxtoolbox.com/SuperTool.aspx (opens new window)
WARNING
On MX Toolbox, "SMTP Test" will give an error because we haven't configurated Exim4 yet. We will fix this through this tutorial.
Exim4
sudo apt-get install exim4 exim4-base exim4-config exim4-daemon-heavy
Run:
sudo dpkg-reconfigure exim4-config
interfaces
, you need to leave it empty.split files?
, you need to answer YES!!!
./etc/exim4/update-exim4.conf.conf
dc_eximconfig_configtype='internet'
dc_other_hostnames='example.com;example2.com'
dc_local_interfaces=''
dc_readhost=''
dc_relay_domains=''
dc_minimaldns='false'
dc_relay_nets=''
dc_smarthost=''
CFILEMODE='644'
dc_use_split_config='false'
dc_hide_mailname=''
dc_mailname_in_oh='true'
dc_localdelivery='mail_spool'
dc_other_hostnames
is optional. You can leave it blank or even incomplete, but if you want to fill it:
example.com
and example2.com
with your actual domains.dc_other_hostnames='example.com'
sudo rm /etc/exim4/exim4.conf
/var/lib/exim4/config.autogenerated
)sudo update-exim4.conf
/etc/valias
sudo mkdir /etc/valias
/etc/valiases
sudo nano /etc/valiases/example.com
Contents:
bob: [email protected]
pam: [email protected]
info: [email protected], [email protected]
*: [email protected], [email protected]
TIP
Notice the *
at the last line. It's a catch-all email address. It's optional and it means that any email that doesn't match the above rules will end up there. For example, [email protected]
will be sent to bob
and pam
in this configuration.
/etc/exim4/conf.d/main/01_exim4-config_listmacrosdefs
Set the virtual aliases directory (/etc/valiases
):
#domainlist local_domains = MAIN_LOCAL_DOMAINS
domainlist local_domains = @:localhost:dsearch;/var/mail/virtual:dsearch;/etc/valiases
/etc/exim4/conf.d/router/350_exim4-config_vdom_aliases
vdom_aliases:
driver = redirect
allow_defer
allow_fail
domains = dsearch;/etc/valiases
data = ${expand:${lookup{$local_part}lsearch*@{/etc/valiases/$domain}}}
retry_use_local_part
pipe_transport = address_pipe
file_transport = address_file
no_more
/etc/hosts
(OPTIONAL – just for speed sake)127.0.1.1 example.com
127.0.1.1 example2.com
exim4
servicesudo /etc/init.d/exim4 restart
sudo exim -bt -d-resolver [email protected]
See logs with:
tail -f /var/log/exim4/mainlog
Check with an external tool: https://mxtoolbox.com/SuperTool.aspx (opens new window)
If you want to enable TLS, you can use this tutorial and a CAcert.org
SSL cert for free:
https://github.com/Exim/exim/wiki/EximServerSslCertificate (opens new window)