It is quite a pain to setup email forwarding in DigitalOcean with not much experience in command line. Moreover, many tutorials online are outdated or didn’t provide right configuration. This is the guide to setup Postfix for email forwarding which I tested and tried many times.
Step 1: Install Postfix
Run this (in Ubuntu)
sudo apt-get update sudo apt-get install postfix
Step 2: Choose ‘Internet Site’ for configuration
There will be pink screen for mail configuration pop after we have installed Postfix.
Follow these configurations:
General type of mail configuration: Internet Site
System mail name: example.com
Root and postmaster mail recipient: <admin_user_name> e.g. root
Other destinations for mail: example.com, localhost.example.com, localhost
Force synchronous updates on mail queue?: No
Local networks: 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
Mailbox size limit (bytes): 0
Local address extension character: +
Internet protocols to use: all
Step 3: Edit config file
Edit /etc/postfix/main.cf using command:
sudo nano /etc/postfix/main.cf
Add 2 more lines at the bottom:
virtual_alias_domains = example.com virtual_alias_maps = hash:/etc/postfix/virtual
Step 4: Setup forwarding email address
Add forwarding email addresses using the following command:
sudo nano /etc/postfix/virtual
At the beginning, this file should be empty. Then add 1 forward email addresses per line.
email@example.com firstname.lastname@example.org email@example.com firstname.lastname@example.org
Note: Hotmail usually block postfix forwarder (it might work at the first time, but it will fail to work after a while).
Solution for Hotmail:
- Set SMTP Relay (3rd party SMTP service) to send an email, but some SMTP service block sending domain that is not your own domain.
- Simple. Just create new gmail account and set auto-forward to hotmail.
We are almost there! Save and quit.
Step 5: Refresh Postfix
Run this command:
sudo postmap /etc/postfix/virtual sudo service postfix restart
Test sending email to your forwarded address e.g. email@example.com. It should be forwarded to firstname.lastname@example.org !
Also published on Medium.