Create BCC of incoming and outgoing mails without knowing the users - Postfix



BCC to Boss Function - Postfix


Postfix provides three mechanisms:

    always_bcc = address
        Deliver a copy of all mail to the specified address.
    sender_bcc_maps = type:table
        Search the specified "type:table" lookup table with the envelope sender address for an automatic BCC address.
    recipient_bcc_maps = type:table
        Search the specified "type:table" lookup table with the envelope recipient address for an automatic BCC address.

These features are implemented in postfix 2.1 and later versions.

always_bcc

Add the following entry in /etc/postfix/main.cf to forward all mails in the server to administrator@example.com.

always_bcc = administrator@example.com



sender_bcc_maps and recipient_bcc_maps


You can setup these functions as follows.

[root@postfix ~]# touch /etc/postfix/sender_bcc
[root@postfix ~]# touch /etc/postfix/recipient_bcc

[root@postfix ~]# postmap sender_bcc
[root@postfix ~]# postmap recipient_bcc


Then, open /etc/postfix/main.cf and add the following lines in it.


sender_bcc_maps = hash:/etc/postfix/sender_bcc
recipient_bcc_maps = hash:/etc/postfix/recipient_bcc


verify the following files are generated once the above steps are finished.

/etc/postfix/recipient_bcc.db
/etc/postfix/sender_bcc.db

You can add entries as like follows in sender_bcc and recipient_bcc. This will forward mails from user@domain.com to other@example.com.

[root@postfix ~]# cat /etc/postfix/sender_bcc
user@domain.com other@example.com

[root@postfix ~]# cat /etc/postfix/recipient_bcc
user@domain.com other@example.com


Finally reload postfix,

[root@postfix ~]# postfix reload




Reference:
http://www.postfix.org/ADDRESS_REWRITING_README.html

4 thoughts on “Create BCC of incoming and outgoing mails without knowing the users - Postfix”

  1. Thanks for the example. Instead of creating the two db files, would this work?

    sender_bcc_maps = inline:{someone@example.com, {boss@example.com}}
    recipient_bcc_maps = inline:{someone@example.com, {boss@example.com}}

    Thanks,
    j

  2. thanks.

    it's not working.
    i get this warning in the log file

    Dec 16 11:51:33 SERVERADRESS postfix/cleanup[25062]: warning: database /etc/postfix/sender_bcc.db is older than source file /etc/postfix/sender_bcc

    Dec 16 11:51:33 SERVERADDRES postfix/cleanup[25062]: warning: database /etc/postfix/recipient_bcc.db is older than source file /etc/postfix/recipient_bcc

    any suggestions?