用 SPF + Greylisting 给 Postfix 阻挡垃圾邮件

某域名十多年的邮件服务。期间硬件和软件换了好几次。近期将要停止服务。可能这次启用 SPF + greylisting 是我给此域名做的最后一次邮件服务配置了。

安装(Debian下)

$ sudo aptitude install postgrey postfix-policyd-spf-python

配置

  • /etc/postfix/main.cf
[...]
policyd-spf_time_limit = 3600
smtpd_restriction_classes = mfrom_passed_spf
smtpd_recipient_restrictions =
        [...]
        reject_unauth_destination,
        # 一定要放 在reject_unauth_destination 后
        #否则会成为 open relay
        check_policy_service unix:private/policyd-spf,
        check_policy_service inet:127.0.0.1:60000,
        # 后续检查
        [...]
        permit
mfrom_passed_spf =
        # 后续检查
        [...]
        permit

使用 Postfix Restriction Class,只有 SPF 返回值不是 Pass (即 SPF 中性或临时错误)时才检查 greylisting 策略,这样可以减少 greylisting 延迟带来的用户体验变差。

  • /etc/postfix-policyd-spf-python/policyd-spf.conf
[...]
Mail_From_reject = Fail
Mail_From_pass_restriction = mfrom_passed_spf

要注意 policyd-spf.conf 中字段名和值的大小写。

  • /etc/postfix/master.cf
[...]
policyd-spf     unix    -       n       n       -       0       spawn
        user=policyd-spf argv=/usr/bin/policyd-spf

也许用 ppolicy 更合理一点,一个模块化的 policy server 完成多种功能,通过 Python 脚本来配置检查流程。不过看起来比较复杂,也不知道以后有没有机会玩了。

评论

发表新评论

此内容将保密,不会被其他人看见。
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.