提升 Debian 系统发信速度,主要取决于你使用的是 Postfix / Exim / Sendmail 等哪一类 MTA,以及发信是 本机、内网还是外发(公网)。下面按**最常见场景(Postfix)**给出系统化的优化方案,同时也适用于其他 MTA 的通用思路。
先定位瓶颈,再优化,否则容易白忙活。
# 查看队列是否堆积
mailq
# 查看实时发信日志
journalctl -u postfix -f
# 或
tail -f /var/log/mail.log
常见慢点:
postconf -e "default_process_limit = 20"
postconf -e "smtp_destination_concurrency_limit = 10"
postconf -e "smtp_destination_rate_delay = 0s"
说明:
smtp_destination_concurrency_limit:同一目标并发连接数smtp_destination_rate_delay:每封信之间的延迟(建议 0)postconf -e "smtp_mx_session_limit = 5"
postconf -e "smtp_connect_timeout = 10s"
postconf -e "smtp_timeout = 30s"
避免因为某个目标服务器慢而拖慢整体。
如果是 内网发信 或 批量通知邮件:
postconf -e "smtpd_relay_restrictions = permit"
postconf -e "smtpd_recipient_restrictions = permit"
⚠️ 公网发信慎用,否则容易被当垃圾邮件服务器。
postconf -e "reject_rbl_client = "
postconf -e "smtpd_client_restrictions = permit"
DNS 慢 = 发信慢
cat /etc/resolv.conf
建议使用:
关闭 IPv6(如果不用):
postconf -e "inet_protocols = ipv4"
postconf -e "smtp_line_length_limit = 2048"
postconf -e "queue_directory = /var/spool/postfix"
如队列大,可将部分队列放内存:
mount -t tmpfs tmpfs /var/spool/postfix/incoming
⚠️ 重启会丢队列,仅适合允许丢信的场景。
postconf -e "qmgr_message_active_limit = 20000"
postconf -e "qmgr_message_recipient_limit = 20000"
推荐使用:
PHP 示例(最快):
mail($to, $subject, $body);
或:
sendmail -t
postconf -e "smtp_destination_rate_delay = 0s"
postconf -e "smtp_extra_recipient_limit = 100"
常见优化:
# 增大并发
smtp_accept_queue = 100
smtp_accept_max = 50
| 场景 | 参考速度 |
|---|---|
| 内网裸发 | 500–2000 封/秒 |
| 本机 SMTP | 50–200 封/秒 |
| 公网批量 | 30–100 封/秒(受目标限制) |
你可以直接告诉我:
postconf -n 输出我可以 直接给你一套可执行的优化配置,不踩坑。