From Notes Wiki
Jump to: navigation, search
Home > CentOS > CentOS 6.x > Postfix server configuration > Forwarding or copying of emails

Forwarding or copying of emails

Copy all emails received by a user to other accounts

A copy of all emails received by user can be sent to other accounts. This can be done by creating a '.forward' file in users home folder. In this file an email address can be specified per line where the mails should be forwarded. For example for user saurabh a .forward could look like:

barjatiya.saurabh@gmail.com
root
saurabh@sbarjatiya.com
saurabh

where a copy of each received email would get forwarded to barjatiya.saurabh@gmail.com, user root on same system, saurabh@sbarjatiya.com and a copy of email would be present in user saurabh mail box. The name of same user, ie saurabh, in this case must come at end. We cannot put the same name in any other (non-last) line.

Also if only forwarding is desired and a copy of email in user saurabh's inbox is not required than we can omit specifying 'saurabh' at end. Note that if copy of email is not required then using aliases from /etc/alises might be simpler for forwarding email to other accounts or addresses.


Copy all incoming emails from email server to an email account

In case of a company it might be desired to copy all incoming emails, or copy all incoming emails from non-company domain to a special monitoring account. This can be done as follows:

  1. Edit /etc/postfix/main.cf and append:
    recipient_bcc_maps = regexp:/etc/postfix/recipient_bcc_maps
  2. Create '/etc/postfix/recipient_bcc_maps' with line similar to:
    !/^member@sbarjatiya\.com$/ member@sbarjatiya.com
    This would ensure that a copy of all incoming emails (except emails coming from member@sbarjatiya.com to avoid forwarding loops) are sent to member@sbarjatiya.com transparently. For only non-domain emails one can use simpler regular expression such as:
    !/^.*@sbarjatiya\.com$/ member@sbarjatiya.com
  3. Restart postfix

The avoiding of forwarding loop is precautionary. As such postfix is intelligent and distinguishes from mail sent / received by itself vs. mails send / received from outside. So loops using bcc_maps should not happen even with simple configurations.

For other types of tables other than regexp as use here refer to http://www.postfix.org/DATABASE_README.html#types


Copy all outgoing emails from email server to an email account

In case of a company it might be desired to copy all outgoing emails, or copy all outgoing emails from non-company domain to a special monitoring account. This can be done as follows:

  1. Edit /etc/postfix/main.cf and append:
    sender_bcc_maps = regexp:/etc/postfix/sender_bcc_maps
  2. Create '/etc/postfix/sender_bcc_maps' with line similar to:
    !/^member@sbarjatiya\.com$/ member@sbarjatiya.com
    This would ensure that a copy of all ougoing emails (except emails sent from member@sbarjatiya.com to avoid forwarding loops) are sent to member@sbarjatiya.com transparently. For only non-domain emails one can use simpler regular expression such as:
    !/^.*@sbarjatiya\.com$/ member@sbarjatiya.com
  3. Restart postfix


The avoiding of forwarding loop is precautionary. As such postfix is intelligent and distinguishes from mail sent / received by itself vs. mails send / received from outside. So loops using bcc_maps should not happen even with simple configurations.

For other types of tables other than regexp as use here refer to http://www.postfix.org/DATABASE_README.html#types


Copy all external emails (sent or received) to an email account

To copy all external emails use 'always_bcc' instead of 'receipient_bcc_maps' or 'sender_bcc_maps' as explained above.



Steps learned from http://www.linuxquestions.org/questions/linux-software-2/postfix-copy-all-outgoing-mail-to-admin-account-583868/