Redirect specific e-mail address sent to a user, to another user

I need to redirect e-mail within our MTA when the two following criteria are both true:

When an e-mail is:

Result: redirect e-mail to [email protected].

I don't want to catch *@isp.com and redirect, and I don't want to redirect all e-mail addressed to [email protected] but only redirect when [email protected] sends [email protected] 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?


Solution 1:

You can use PCRE In /etc/postfix/main.cf:

header_checks = pcre:/etc/postfix/headers_check

/etc/postfix/headers_check:

/To:.*@(?!mail.domain.com) && From:.*@?!extdomain.com/ REDIRECT [email protected]

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

Solution 2:

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

/etc/postfix/main.cf:

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:

[email protected]                   redirect

/etc/postfix/maps/redirections:

[email protected]            [email protected]

For more information see: http://www.postfix.org/RESTRICTION_CLASS_README.html