Forwarding email for self-hosting multiple domains using Ubuntu
So I switched from a shared host (which was slow), to a new dedicated Digital Ocean server, which is great, but what will happen to my emails?
I found the following which describes how to set up Postfix for forwarding emails. Here are my instructions on how to get it working:
Firstly, install postfix:
sudo apt-get insall postfix
You should select “Internet Site” and put the (or one of the) domain names that your box hosts in the next bit.
Once installed, edit the below file:
sudo vi /etc/postfix/main.cf
and add the following lines with all the domains you are serving:
virtual_alias_domains = ham1.co.uk anotherdomain.com evenmore.co.uk
virtual_alias_maps = hash:/etc/postfix/virtual
Next you will need to edit the following:
sudo vi /etc/postfix/virtual
You can either set up specific email addresses or a ‘catch-all’ by omitting anything before the ‘@’ e.g.:
sudo postmap /etc/postfix/virtual
sudo service postfix reload
If you have UFW configured (or IPTables etc.) then make sure you allow traffic in on port 25:
sudo ufw allow mail
Finally, create the MX record in the DNS record for your domain(s). I simply chose to point them at the hostname of the domain (the A record) and not the IP address of the server.