We have a setup where postfix sends mails via Amazon SES relay. All is working fine except email forwards.
The problem is that Amazon SES won't send emails, where
From: is not verified. So when an internal address wants to forward to an external and the sender is external as well, the mail will not get sent.
To solve this, we currently use the following config in main.cf
header_checks = regexp:/etc/postfix/first_header_checks smtp_header_checks = regexp:/etc/postfix/second_header_checks sender_canonical_maps = regexp:/etc/postfix/sender_canonical sender_canonical_classes = envelope_sender smtpd_data_restrictions = check_sender_access pcre:/etc/postfix/sender_access
/^From:(\s)?(.*)/i PREPEND X-Original-From: $2 /^To:(\s)?(.*)$/i PREPEND X-Original-To: $2
/^From:(.*)/i REPLACE From: <firstname.lastname@example.org>
/(.*)/ prepend Reply-To: <$1>
This works great for incoming mail. email@example.com sends the mail to firstname.lastname@example.org and it gets forwarded to email@example.com
Reply-To: <firstname.lastname@example.org> X-Original-To: <email@example.com> To: firstname.lastname@example.org From: <email@example.com> X-Original-From: <firstname.lastname@example.org>
The problem, this also happens for outgoing mail from the server. Say email@example.com sends a mail, the from gets rewritten to no-reply and a Reply-To will be set. This I want to fix. The mail headers should only be rewritten for incoming mail that will be forwarded.
I have tried using regular expressions like
!/^From:(\s)?(.*@verified-domain\.com)/ but so far with no luck.