Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 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 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 (and also on other addresses, such as I'd like to move the original From header to the Reply-To header, and then change the From header to (or something like this). For example:

From: "Bruce Wayne" <>
To: "MySite Support" <>

Would become

From: "Mail Services" <>
Reply-To: "Bruce Wayne" <>
To: "MySite Support" <>

I have 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

  1. conditionally rewriting based upon the address of the To header and
  2. 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: (|
/^From:(.+@.+).*$/ PREPEND Reply-To:$1
/^From:(.+@.+).*$/ REPLACE From:

I've added the following line to

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?

share|improve this question

The IF pattern matches the same line as other patterns between IF and ENDIF do, so you cannot mix To: and From: headers in the statement. See BUGS in header_checks(5) man page.

share|improve this answer

While I haven't tested your specific setup, I'm pretty sure the To regex should match on the full header. That is, it looks to me like you're matching only the case where there is a bare email address. If you want to match 'To: "MySite Support" <>', then you will have to use:

if /^To:.*(|

or something more complicated that rules out "" and such.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.