Postfix configuration – keep the envelops

emailforwardingpostfix

I have a postfix server that delivers mail and send a copy of the outgoing mail to a second server for content analysis using the following configuration (addresses and IPs have been replaced):

main.cf content

sender_bcc_maps = pcre:/$config_directory/sender_bcc

sender_bcc content

/^(.*)@(.*)$/                   ${1}@tst.example.com

transport_maps content

tst.example.com     smtp:[192.168.1.1]

Unfortunately, the configuration above doesn't preserve the envelop so I don't get the original recipient on the second server.
The goal in having the original recipient is to catch BCCs. Is there a way to do it just by configuring Postfix?
An example of a good result would be to have postfix add something like

x-bcc: test@example.com
or
x-original-recipient: test@example.com

to the email headers sent to the second server (and only them. We don't want to add a bcc header or anything like that to the email that is delivered to the users, obviously).

I've looked everywhere and haven't found anything to add the original recipient. Maybe there's another way? Any suggestion to reach the final goal is welcome!

Best Answer

To enable postfix to save the original recipient of the mail, you can add the following line to your main.cf:

enable_original_recipient = yes

After this, your mail contains the following header:

X-Original-To: original.recipient@your.mailhost.com

But for content filtering or inspection, you should have a look at the milter interface (before you accept and queue a mail) of Postfix or the content_filter directive (after you accepted and queued a mail).

Related Question