如果以下两个条件都为真,我需要在MTA中redirect电子邮件:
当电子邮件是:
结果:将电子邮件redirect到[email protected]。
我不想捕获*@isp.com并redirect,我不想redirect到[email protected]的所有电子邮件,只有在[email protected]发送[email protected]时才会redirect电子邮件。
我如何在Postfix的configuration中实现这一点。 如果在Postfix中不可能,最好的解决scheme是什么?
你可以使用PCRE在/etc/postfix/main.cf中:
header_checks = pcre:/etc/postfix/headers_check
/等/后缀/ headers_check:
/To:.*@(?!mail.domain.com) && From:.*@?!extdomain.com/ REDIRECT [email protected]
PCRE使用perl定期扩展,您可以指定任何条件。
如果你不想使用procmail,那么也许你想要的东西如下所示:
/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 /后缀/地图/ user_to_redirect:
[email protected] redirect
在/ etc /后缀/地图/redirect:
[email protected] [email protected]
有关更多信息,请参阅: http : //www.postfix.org/RESTRICTION_CLASS_README.html
你用procmail考虑过吗? 请点击这里 ,让我们知道这是否能满足您的需求。
具体而言,结合“转发”指令,将邮件推送到另一个地址,使用“垃圾邮件”部分来识别正确的电子邮件,似乎正是您要查找的内容。
我的后缀没有安装pcre:
fatal: dict_open: unsupported dictionary type: pcre: Is the postfix-pcre package installed?
但基本的正则expression式的工作,如下所述:
main.cf
header_checks = regexp:/etc/postfix/header_checks The syntax in the header_checks file is: /regex_pattern/ ACTION
http://mattshaw.org/news/how-to-filter-mail-with-postfix-header_checks/
也要注意,用户名称出现在标题行的From From开始的电子邮件地址之前,例如:
From: Mr Smith <[email protected]>
所以你的正则expression式将需要考虑到这一点。
但是,我发现一个简单的解决scheme,不需要正则expression式,只要你不介意不能控制基于收件人的规则。
在现代版本的Postfix中,您可以将redirect命令添加到sender_access
假设你在你的main.cf中有这样一行:
smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender_access
您可以添加一行到sender_accessredirect电子邮件到另一个地址,如下所示:
[email protected] REDIRECT [email protected]
只要记得在保存sender_access后做postmap hash:sender_access即可
这是将所有邮件从extdomain1.ltd转发到特殊邮箱[email protected]的工作configuration:
#cat main.cf .. header_checks = pcre:/etc/postfix/header_checks .. #cat /etc/postfix/header_checks /From:.*@extdomain1.ltd/ REDIRECT [email protected]
不要忘记发送更新postfix命令重新读取configuration。
问题在于它只能用任何一种方法redirect到一个电子邮件地址。
[email protected] REDIRECT [email protected]
例如下面的代码就不能工作了,因为它在Postfix中非常有限:
[email protected] REDIRECT [email protected] | [email protected]
如果你要做一些更花哨的东西,我强烈build议你安装并学习如何使用procmail。