sendmail 发送电子邮件失败 - CentOS 7

sendmail 发送电子邮件失败 - CentOS 7

我发送邮件的简单 PHP 脚本是

<?php
    ini_set( 'display_errors', 1 );
    error_reporting( E_ALL );
    $from = "[email protected]";
    $to = "[email protected]";
    $subject = "PHP Mail Test script";
    $message = "This is a test to check the PHP Mail functionality";
    $headers = "From:" . $from;
    mail($to,$subject,$message, $headers);
    echo "Test email sent";
?>

当我在任何其他服务器上运行此脚本时,它运行良好,但在我的新 CentOS 7 机器上执行时,我总是在 /var/log/maillog 中收到错误

Mar 15 19:08:38 host sendmail[1521]: u2FN8cfK001521: from=root, size=23, class=0, nrcpts=1, msgid=<[email protected]>, relay=root@localhost
Mar 15 19:08:38 host sendmail[1522]: u2FN8cTc001522: from=<[email protected]>, size=328, class=0, nrcpts=1, msgid=<[email protected]>, proto=ESMTP, daemon=MTA, relay=localhost.localdomain [127.0.0.1]
Mar 15 19:08:38 host sendmail[1521]: u2FN8cfK001521: [email protected], ctladdr=root (0/0), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30023, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (u2FN8cTc001522 Message accepted for delivery)
Mar 15 19:08:38 host sendmail[1524]: STARTTLS=client, relay=gmail-smtp-in.l.google.com., version=TLSv1/SSLv3, verify=FAIL, cipher=ECDHE-RSA-AES128-GCM-SHA256, bits=128/128
Mar 15 19:08:39 host sendmail[1524]: u2FN8cTc001522: to=<[email protected]>, ctladdr=<[email protected]> (0/0), delay=00:00:01, xdelay=00:00:01, mailer=esmtp, pri=120328, relay=gmail-smtp-in.l.google.com. [IPv6:2607:f8b0:400d:c06::1a], dsn=5.0.0, stat=Service unavailable
Mar 15 19:08:39 host sendmail[1524]: u2FN8cTc001522: u2FN8dTc001524: DSN: Service unavailable
Mar 15 19:08:39 host sendmail[1524]: u2FN8dTc001524: to=<[email protected]>, delay=00:00:00, xdelay=00:00:00, mailer=local, pri=31588, dsn=2.0.0, stat=Sent

答案1

与其他公共邮件服务器(Yahoo!、Hotmail)不同,Gmail 似乎必须验证 SPF 记录下的相应 IP 地址。由于 sendmail 一直通过 IPv6 发送电子邮件,因此 SPF 记录中没有该 IP 地址。因此,我所做的只是将 IPv6 添加到 SPF 记录中,一切顺利。

所以,现在我的 SPF 记录看起来像这样

v = spf1 mx a ip6:2547:2200:60:9a2a :: / 64 ip4:44.33.33.104/32 a:mail.example.org include:example.org ~all

相关内容