Typical thing when having a new site up: you want to get email@example.com 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.
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: [yourdomain.com] (no subdomain)
SMTP relay host: [smtp.yourprivider.com] (only showing if you chose “Internet with smarthost”)
Root and postmaster mail recipient: The
Other destinations to accept mail for: keep the suggested defaults and add in front [yourdomain.com] 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
All edits with
sudo if you not logged in as root.
/etc/postfix/main.cf add following two lines to the end
virtual_alias_domains = [yourdomain.com] virtual_alias_maps = hash:/etc/postfix/virtual
/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.