Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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 need to redirect e-mail within our MTA when the two following criteria are both true:

When an e-mail is:

  • Sent from:
  • Addressesd to:

Result: redirect e-mail to

I don't want to catch * and redirect, and I don't want to redirect all e-mail addressed to but only redirect when sends an e-mail.

How do I achieve this within Postfix's configuration. And if it's not possible within Postfix, what may be the best solution?

share|improve this question
up vote 4 down vote accepted

You can use PCRE In /etc/postfix/

header_checks = pcre:/etc/postfix/headers_check


/To:.*@(?! && From:.*@?! REDIRECT

PCRE works with perl regular extentions, and you can specify any conditions.

share|improve this answer
Sure the "&&" operator does work? Found nothing in the header_checks manpage and everything not documented in Postfix doesn't exist. I'm afraid I cannot falsify this with a test at the moment. – sebokopter Jun 28 '11 at 15:27
Likely, correctly will be as follows: 'm/To:.*@(?! && m/From:.*@(?!' But I can't verify this on realy work server. And you have to replace "To:.*@(?!" to you normal address. – Cucumber Jun 28 '11 at 18:08
Is it possible to redirect to more than one email-address and to deliver to the original recipient? – harp Oct 20 '14 at 13:13
The voted answer will not work because postfix checks one header at a time, as the manual clearly states. – bserem Sep 14 '15 at 5:45

If you don't want to use procmail then maybe you want something like the following:


smtpd_restriction_classes = redirect
redirect = check_recipient_access hash:/etc/postfix/maps/redirections
smtpd_recipient_restrictions = [...some checks...],
                               check_sender_access hash:/etc/postfix/maps/user_to_redirect,
                               [...some more checks...]

/etc/postfix/maps/user_to_redirect:                   redirect


For more information see:

share|improve this answer

have you considered a .forward with procmail? Check here and let us know if this answers your need.

Specifically, combining the "Forwarding" instructions, for pushing mail back out to another address, with the "Spam" section, for identifying the correct emails, would seem to do exactly what you're looking for.

share|improve this answer

My postfix didn't have pcre installed:

fatal: dict_open: unsupported dictionary type: pcre:  Is the postfix-pcre package installed?

But the basic regex ones worked, as outlined here:

header_checks = regexp:/etc/postfix/header_checks

The syntax in the header_checks file is:
/regex_pattern/ ACTION

Be aware too that the users name comes before the email address in the header line starting with From, eg:

From: Mr Smith <>

So your regex will need to take that into account.

But I found a simpler solution that doesn't require regexes as long as you don't mind not being able to control the rule based on the recipient.

In modern versions of postfix you can add a redirect command to sender_access

Assuming you have a line in your like so:

smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender_access

You can add a line to sender_access to redirect the email to another address like so: REDIRECT

Just remember to do postmap hash:sender_access after saving sender_access

share|improve this answer

The problem with it all is that it can only redirect to one single email address with either of the methods at all. REDIRECT

for example the following will not work already as it's pretty much limited in Postfix: REDIRECT |

If your are to do some more fancy stuff I'd strongly suggest that your install and learn how to use procmail.

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.