Linux 网络服务器,运行本地 postfix 邮件服务器,apache 上的 PHP 网络系统。Postfix 配置为将电子邮件传递给 spampd 进行垃圾邮件检查,但本地网络除外:
smtp inet n - y - 20 smtpd
-o smtpd_proxy_filter=127.0.0.1:10025
-o smtpd_client_connection_count_limit=10 127.0.0.1:10026 inet n - n - - smtpd
-o smtpd_authorized_xforward_hosts=127.0.0.0/8
-o smtpd_client_restrictions=
-o smtpd_helo_restrictions=
-o smtpd_sender_restrictions=
-o smtpd_recipient_restrictions=permit_mynetworks,reject
-o smtpd_data_restrictions=
-o mynetworks=127.0.0.0/8
-o receive_override_options=no_unknown_recipient_checks
这适用于我们所有的网络系统,除了最新的系统,该系统运行的是 Yii2 和 Swiftmailer。来自此系统的电子邮件被不必要地传递给 spampd,这大大减慢了响应时间。
以下是显示该问题的典型邮件日志:
Sep 17 10:37:33 ip-172-31-12-147 postfix/smtpd[28970]: connect from localhost[127.0.0.1]
Sep 17 10:37:33 ip-172-31-12-147 postfix/smtpd[28990]: NOQUEUE: client=localhost[127.0.0.1]
Sep 17 10:37:33 ip-172-31-12-147 postfix/smtpd[28970]: E3526409A9: client=localhost[127.0.0.1], orig_client=localhost[127.0.0.1]
Sep 17 10:37:33 ip-172-31-12-147 spampd[23514]: processing message <[email protected]> for <***@cbdweb.net>
Sep 17 10:37:39 ip-172-31-12-147 spampd[23514]: clean message <[email protected]> (-102.90/5.00) from <***@cbdweb.net> for <***@cbdweb.net> in 5.14s, 1250 bytes.
Sep 17 10:37:39 ip-172-31-12-147 postfix/cleanup[28971]: E3526409A9: message-id=<[email protected]>
Sep 17 10:37:39 ip-172-31-12-147 postfix/qmgr[20013]: E3526409A9: from=<***@cbdweb.net>, size=1753, nrcpt=1 (queue active)
Sep 17 10:37:39 ip-172-31-12-147 postfix/smtpd[28990]: proxy-accept: END-OF-MESSAGE: 250 2.0.0 Ok: queued as E3526409A9; from=<***@cbdweb.net> to=<***@cbdweb.net> proto=ESMTP helo=<alpinebookings.cbdweb.net>
Sep 17 10:37:39 ip-172-31-12-147 postfix/smtpd[28970]: disconnect from localhost[127.0.0.1] ehlo=1 xforward=1 mail=1 rcpt=1 data=1 quit=1 commands=6
Sep 17 10:37:39 ip-172-31-12-147 postfix/smtpd[28990]: disconnect from localhost[127.0.0.1] ehlo=1 mail=2 rcpt=2 data=2 quit=1 commands=8
Sep 17 10:37:39 ip-172-31-12-147 postfix/smtp[28983]: E3526409A9: to=<***@cbdweb.net>, relay=ip-172-31-11-15.ap-southeast-2.compute.internal[172.31.11.15]:25, delay=5.2, delays=5.2/0/0.01/0, dsn=2.0.0, status=sent (250 Message accepted for delivery)
Sep 17 10:37:39 ip-172-31-12-147 postfix/qmgr[20013]: E3526409A9: removed
与同一服务器上的 wordpress 网站发送的电子邮件进行比较:
Sep 17 11:00:04 ip-172-31-12-147 postfix/pickup[27803]: 33917409AA: uid=33 from=<apache>
Sep 17 11:00:04 ip-172-31-12-147 postfix/cleanup[30456]: 33917409AA: message-id=<[email protected]>
Sep 17 11:00:04 ip-172-31-12-147 postfix/qmgr[20013]: 33917409AA: from=<***@cbdweb.net>, size=847, nrcpt=1 (queue active)
Sep 17 11:00:24 ip-172-31-12-147 postfix/smtp[30458]: 33917409AA: to=<***@***.com>, relay=mx1.***.com.au[103.240.135.130]:25, delay=20, delays=0.05/0/0.08/20, dsn=2.0.0, status=sent (250 Ok: queued as 2F3701100075)
Sep 17 11:00:24 ip-172-31-12-147 postfix/qmgr[20013]: 33917409AA: removed
邮件程序的Yii2配置是:
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => $params['level'] === 'DEV' ? '***.cbdweb.net' : '127.0.0.1',
'port' => '25'
],
],
答案1
除了使用 sendmail 之外,还可以使用 postfix 监听 milter 输出的 SMTP 端口来避免 milter(邮件过滤器)问题。我在以下后续问题的回答中对此进行了充分解释:当连接来自本地主机时,如何阻止 postfix 将邮件转发到 spampd