Saturday, January 20, 2018

Setup mail forwarding in postfix on Debian or Ubuntu

Install Postfix
$ sudo apt-get install postfix
After Install check postfix status
$ sudo service postfix status

Further check that postfix is running a server on port 25 with the netstat command
$ sudo netstat -ltnp | grep 25
Output : 
tcp        0      0*    LISTEN      1926/master     
tcp6       0      0 ::1:25            :::*         LISTEN      1926/master
Verify DNS settings of domain
$ sudo dig mx

Configure postfix to forward mails

Check the path of config folder using  postconf command
$ postconf | grep config_directory
config_directory = /etc/postfix

Edit the file and add following lines at end if  it

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

Now Create /etc/postfix/virtual file and add emails to forwad along with destination mails like:

First mail  address receive emails, and the second address would forward the emails.

For all forward emails use following lines 

After this save file and close it and run following commands

$ postmap /etc/postfix/virtual
$ sudo service postfix reload.

Now try to send an email from somewhere to the address on yourdomain and the same mail forwarded to other account.