Postfix Pipe then forward to original recipient

I may well be on the wrong track here with what I'm trying to do, so I'd appreciate any advice.

Is it possible to pipe email to a script (which I have working), and then have Postfix forward it on to its original recipient using transport_maps, virtual_alias_maps or some other Postfix type thing?

Looking at the Postfix mailflow diagram, the answer is probably no because Pipe does not then go on to re-queue the message. Therefore my question is, if not, then what is the best way of doing what I am trying to do? Should my piped script (which basically dumps the email content to a text file) also be in charge of sending this on using something like sendmail? Or is there a better way?

Many thanks


Solution 1:

You can use feature always_bcc. Add this parameter in main.cf.

always_bcc = [email protected]

Then you can put [email protected] to the alias file e.g /etc/aliases

mypipe: "|/path/to/myscript.sh"

Don't forget to postalias the alias file.

Note: domain example.com should be a local domains, because pipe must be in local classes domain

UPDATE

If your case is sender-dependent script or recipient-dependent script, you can use the variations of always_bcc, they are recipient_bcc_maps for recipient-dependent script or sender_bcc_maps for sender-dependent script