I've got a web app running on Amazon AWS and it's using Amazon SES to send emails. One of the things I really want this system to do is to be able to forward emails to certain addresses from anyone who mails it, for example if some random person emails firstname.lastname@example.org then I want it to forward to my personal email address.
I tried to do this with aliases, but it doesn't work due to restrictions in Amazon SES which disallow me from sending mail from un-verified senders. It works fine if I email email@example.com from an email address that is verified, but not if I email from an unverified address.
So, what I'd like to try to do is rewrite the From and Reply-To headers on any messages that are sent to firstname.lastname@example.org (and also on other addresses, such as email@example.com). I'd like to move the original From header to the Reply-To header, and then change the From header to firstname.lastname@example.org (or something like this). For example:
From: "Bruce Wayne" <email@example.com> To: "MySite Support" <firstname.lastname@example.org>
From: "Mail Services" <email@example.com> Reply-To: "Bruce Wayne" <firstname.lastname@example.org> To: "MySite Support" <email@example.com>
I have firstname.lastname@example.org defined in the aliases file, and it transforms it into my personal email. I'm not sure how the aliases stuff will be affected by header_checks or whatever is needed to solve this.
There is also a catchall alias which sends other emails into my webapp, so this whole header-rewriting stuff is really something that I only need/want for very specific addresses as described above.
Rewriting a single header using regexp seems simple enough, but the things I'm unsure about here are
- conditionally rewriting based upon the address of the To header and
- rewriting the Reply-To header based upon the value of the From header.
Can anyone give me some pointers on how to deal with these two problems? Or if I'm looking at this problem the wrong way, any direction would be much appreciated.
UPDATE - I somehow missed that there are if/endif statements in header_checks. I'm trying to do something like this, but my header checks don't appear to be doing anything:
if /^To: (email@example.comfirstname.lastname@example.org)/ /^From:(.+@.+).*$/ PREPEND Reply-To:$1 /^From:(.+@.+).*$/ REPLACE From: email@example.com endif
I've added the following line to main.cf:
header_checks = pcre:/etc/postfix/header_checks
It's unclear whether I'm supposed to postmap this file. I tried both doing it and not doing it and it made no difference.
Is there something obvious that I'm doing wrong here?