Forward mail with postfixPosted: July 23, 2013
Unconditionally forward (move on) all mail, coming into a mail server for a particular user, to an external e-mail account (e.g. Google Gmail account). The user may be non-existent at the particular server system. Postfix is assumed to be installed and running well.
Open in text editor the file /etc/postfix/main.cf and add two new lines:
virtual_alias_domains = mytestdomain.com
virtual_alias_maps = hash:/etc/postfix/virtual
Substitute mytestdomain.com with your actual domain name for the accounts (actual or virtual) which will have their mail forwarded.
Then make a list of the users (actual or virtual) at this domain who will have their mail forwarded and write their new e-mail destinations. For this you create a new file /etc/postfix/virtual and open it for editing.
In this file you make a very simple list consisting of records like this:
This will make all incoming mail addressed to firstname.lastname@example.org to proceed directly to email@example.com instead. Besides, it does not really matter if the user john does actually have an account at the particular computer of mytestdomain.com.
The final step. Run these two commands for the mail system to process the list you just created and to restart itself:
postmap /etc/postfix/virtual /etc/init.d/postfix reload
Though, at least in particular to Gmail, you may want to reconsider if you actually want to forward mail to their server. Why? You may be taken for a spammer and blacklisted. Read more here.