I set up an email server using postfix and dovecot.

I use an internal domain for internal mails, and address rewriting for outgoing emails. In main.cf, the parameter

smtp_generic_maps = hash:/etc/postfix/generic
and a file "generic" with lines like this:

user <at> mycompany.local	extern_user <at> mydomain.com
As fas as I know, it works, since outgoing emails are sent with the right sender's external address.

I also use sender_bcc_maps to send a copy of all outgoing emails. In main.cf, the parameter

sender_bcc_maps = hash:/etc/postfix/sender
and a file "sender" with lines like this:

extern_user <at> mydomain.com	to_copy <at> mycompany.local
I am pretty sure that this mechanism worked for a time, but I recently noticed that it isn't working anymore.

The problem is that the address rewriting sets the sender's external address AFTER the sender_bcc_maps adds the bcc destinations. So, it never detects an email from mycompany.com, because all of them are sent by mycompany.local.

On the other hand, if I use internal addresses in the generic file, I get a copy of all the emails, including the internal ones.

I'm looking for a way to have a copy of outgoing emails while having sender's address rewriting at the same time. I have already tried using regular expressions, but I have failed so far (i am still trying though).

Any ideas will be welcome.

Thank you indeed.