Postfix 如何限制单用户发信频率?

55 Postfix 如何限制单用户发信频率?
原因

Postfix 自身的 smtpd_client_*rate*_limit 参数只能限制每个 客户端 IP 的连接频率,无法按单个发信用户(SASL 用户名)做限速,因为同一个 IP 背后可能有多个用户。

操作

1. 安装 postfwd 策略服务
apt install postfwd(或从源码安装)
2. 配置 postfwd 规则
编辑 /etc/postfwd/postfwd.cf
id=RATE-01; sasl_username=~.*; action=rate(sender,300/3600/REJECT limit exceeded, 450 4.7.1)
含义:对任何 SASL 认证用户,每 3600 秒内最多发送 300 封,超出则退信 450。
3. 将 Postfix 连接到 postfwd
/etc/postfix/main.cf 中添加:
smtpd_recipient_restrictions =
permit_mynetworks,
permit_sasl_authenticated,
check_policy_service inet:127.0.0.1:10040,
reject_unauth_destination

4. 重启并验证
systemctl restart postfwd postfix
postlog -p INFO "test" 触发策略检查,确认日志中策略服务命中。

RFC 5321 (§4.5.3 Rate Limiting) · postfwd documentation · Postfix SMTPD_ACCESS (README)