Setting up a linux server to forward all incoming mails

Typical thing when having a new site up: you want to get to end up in you normal inbox, say Gmail.

Here are the steps!
Note: If you are logged in as root, you do not need to use “sudo” in front of each command.


It’s recommended to have a user account to receive the mail other than root.
So either choose a user you have created already or create a new one:

sudo adduser [username]

Does your provider require you to use an SMTP relay? (check the documentation, or ask). You need to know this to continue.

Install postfix

Postfix is a software package, a MTA, it handles incoming mail and forwarding.

sudo apt-get install postfix

And answer all configuration questions as below:
Server configuration type: If you use an SMTP relay, choose “Internet with smarthost”, otherwise “Internet”
System mail name: [] (no subdomain)
SMTP relay host: [] (only showing if you chose “Internet with smarthost”)
Root and postmaster mail recipient: The created/chosen before (not root)
Other destinations to accept mail for: keep the suggested defaults and add in front [] and a space
Force synchronous updates on mail queue: no
Local networks: keep suggested
Use procmail for local delivery?: yes
Mailbox size limit: 0
Local address extension character: +
Internet protocols to use: all

Manual configuration

All edits with sudo if you not logged in as root.
Edit /etc/postfix/ add following two lines to the end

virtual_alias_domains = []
virtual_alias_maps = hash:/etc/postfix/virtual

Create/edit /etc/postfix/virtual and add

@[]    []

Finally, after editing this file call

sudo postmap /etc/postfix/virtual

so that postmap actually applies your changes.


If you forward to Gmail, do not use the same address to send test mails that the mails will be forwarded to – Gmail will silently ignore/delete mail where the sender and recipient are the same and you will think the forwarding does not work.