I'm trying to add a rule to Postfix.
My goal is as follows: when anyone EXCEPT (server@example.com) sends an email to (info@example.com) forward it to (sales@example.com). If server@example.com is sending the mail, simply allow it to flow through. To recap, if the sender is NOT server@example.com, redirect the message to sales@example.com. If the sender IS server@example.com, do not redirect.
FYI, info@example.com is an alias, defined in /etc/postfix/virtual which sends to several recipients.
I am using pcre header_checks, but it's simply not working - nothing is happening and all mail is flowing as it was before without being redirected.
If there is a better/easier way to do this, I'm all ears!
So per the instructions in this post and this post I added the following lines to main.cf and headers_check:
main.cf:
header_checks = pcre:/etc/postfix/headers_check
/etc/postfix/headers_check
/To:info@example.com/ && /From:(?(?!server@example.com).)*/ REDIRECT sales@example.com
However, nothing happens. All mail still gets dropped into info@example.com. I removed the 'From' check to see if I could just grab all messages sent to info@example.com and redirect. However, this didn't work either. I ran
postmap -q "From:server@example.com\nTo:info@example.com" pcre:/etc/postfix/headers_check
and received the response
&& /(?(?!server@example.com).)*/ REDIRECT sales@example.com
I also restarted postfix (postfix reload) to ensure it had loaded the configuration.
Also, please note that this is a machine having lots of virtual hosts, each with its own email addresses and aliases. All are combined in /etc/postfix/virtual.
Thanks for any advice on how to accomplish this!