后缀:如何根据发件人redirect一个电子邮件地址

我正在尝试向Postfix添加规则。

我的目标如下:当任何人([email protected])发送一封电子邮件到([email protected])转发到([email protected])。 如果[email protected]正在发送邮件,只需让它通过。 回顾一下,如果发件人不是[email protected],则将邮件redirect[email protected]。 如果发件人是[email protected],则不要redirect。

仅供参考,[email protected]是在/ etc / postfix / virtual中定义的别名,它发送给多个收件人。

我正在使用pcre header_checks,但它根本不起作用 – 没有任何事情发生,所有的邮件像以前一样stream动,而不被redirect。

如果有一个更好/更简单的方法来做到这一点,我是所有的耳朵!

所以根据这篇文章和这篇文章中的说明,我将下面几行添加到了main.cf和headers_check:

main.cf:

header_checks = pcre:/etc/postfix/headers_check 

/等/后缀/ headers_check

 /To:[email protected]/ && /From:(?([email protected]).)*/ REDIRECT [email protected] 

但是,没有任何反应。 所有邮件仍然被放入[email protected]。 我删除了“发件人”检查,看看是否可以抓取所有发送到[email protected]的邮件并redirect。 然而,这也没有工作。 我跑了

 postmap -q "From:[email protected]\nTo:[email protected]" pcre:/etc/postfix/headers_check 

并收到回复

 && /(?([email protected]).)*/ REDIRECT [email protected] 

我也重新启动后缀(后缀重新加载),以确保它已加载configuration。

另外请注意,这是一台拥有大量虚拟主机的机器,每个虚拟主机都有自己的电子邮件地址和别名。 所有的都在/ etc / postfix / virtual中合并。

感谢您有关如何完成此任务的任何build议!

我不知道为什么这个答案被接受和upvoted。 Postfix文档明确指出,postfix一次只检查一个标题行。

这些规则一次对一个逻辑消息头或一个正文行进行操作。 一行的决定不会转移到下一行。

所以,你的想法结合起来和来头是不被Postfix支持的。


另一种方法是在邮件头中使用信封地址代替地址。 要做到这一点,你可以使用称为限制类的后缀function。 看到

在main.cf中添加这一行

 smtpd_restriction_classes = specialsender specialsender = permit smtpd_recipient_restrictions = ... check_sender_access hash:/etc/postfix/mycompany.redirection, check_recipient_access hash:/etc/postfix/redirect.sales ... 

/etc/postfix/mycompany.redirection内容

 [email protected] specialsender 

/etc/postfix/redirect.sales内容

 [email protected] REDIRECT [email protected] 

怎么运行的

当postfix遇到这一行时

 check_sender_access hash:/etc/postfix/mycompany.redirection 

并在specialistder类中find了[email protected],然后postfix允许它不redirect。 另一个电子邮件地址将被检查

 check_recipient_access /etc/postfix/redirect.sales 

如果收件人== [email protected],它将被redirect到[email protected]