How to forward certain emails based on header information with Postfix

mail-forwardingpostfixredirect

We receive service requests via a particular email. The request is then forwarded to other addresses, using an entry in virtual_alias_maps. Upon seeing the word "EMERGENCY" in the subject line of a request to this email, I would also like to forward this to another address (an alias of our administrator's SMS email addresses).

I think I can accomplish this with header checks and the REDIRECT command. However, REDIRECT only sends it to the redirected address, not the forwarded addresses. In the case of "EMERGENCY" I would like it to go to the redirect address and the original forwarded addresses.

I am fairly new to Postfix and I feel like I am missing something here. Any suggestions?

Best Answer

Typically, Postfix won't act upon the message contents without outside help, it acts on the envelope information. Things like the Subject belong to the message contents.

I think the easiest way to manage such things is to include an extra email address to the ones already receiving, which is actually a forward to a script (you can do that in /etc/aliases by prefixing the destination with a pipe symbol, read man aliases) that performs your requested tests on its standard input (the message contents) and acts accordingly.