I'm trying to add a rule to Postfix.
My goal is as follows: when anyone EXCEPT (firstname.lastname@example.org) sends an email to (email@example.com) forward it to (firstname.lastname@example.org). If email@example.com is sending the mail, simply allow it to flow through. To recap, if the sender is NOT firstname.lastname@example.org, redirect the message to email@example.com. If the sender IS firstname.lastname@example.org, do not redirect.
FYI, email@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!
header_checks = pcre:/etc/postfix/headers_check
/To:firstname.lastname@example.org/ && /From:(?(?!email@example.com).)*/ REDIRECT firstname.lastname@example.org
However, nothing happens. All mail still gets dropped into email@example.com. I removed the 'From' check to see if I could just grab all messages sent to firstname.lastname@example.org and redirect. However, this didn't work either. I ran
postmap -q "From:email@example.com\nTo:firstname.lastname@example.org" pcre:/etc/postfix/headers_check
and received the response
&& /(?(?!email@example.com).)*/ REDIRECT firstname.lastname@example.org
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!