Forward mail with postfix

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:
john@mytestdomain.com     john@gmail.com

This will make all incoming mail addressed to john@mytestdomain.com to proceed directly to john@gmail.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

P.S.
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.

Advertisements

One Comment on “Forward mail with postfix”

  1. mulberry コレクション


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s