问题描述
Swiftmailer版本= 6.2.3 PHP版本= 7.4.8
观察到的行为
我正在使用SwiftMailer通过TLS /经过身份验证的通道发送电子邮件,并不断收到以下错误消息。我已经尝试了一些方法,但无济于事。
- “ Swift_Transport_StreamBuffer”“ startTLS”函数中的第94行引发一个异常,内容为:
stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:
error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed
邮件服务器是在我自己的Linux CentOS 7 VM(smtp.ezlista.com)上运行的sendmail服务器。在该sendmail服务器中,我将sendmail配置为在端口587上运行STARTTLS侦听。我已禁用sendmail SSL(端口465)。而且我启用了TLS(端口587)和默认端口25。
使用STARTTLS从Java应用程序发送电子邮件/使用相同的参数进行身份验证时,一切正常。但是,无法通过Swift_Mailer进行相同操作。
在sendmail(linux)服务器端日志中,我注意到在建立STARTTLS通道后出现以下错误,我相信这是在调用Swift_Mailer startTLS()函数之前发生的错误:
Sep 9 17:38:15 vps sendmail[3636]: 089McFtJ003636: <-- EHLO [127.0.0.1]
Sep 9 17:38:15 vps sendmail[3636]: 089McFtJ003636: --- 250-vps.ezlista.com Hello cpe-76-85-14-185.tx.res.rr.com [76.85.14.185],pleased to meet you
Sep 9 17:38:15 vps sendmail[3636]: 089McFtJ003636: --- 250-ENHANCEDSTATUSCODES
Sep 9 17:38:15 vps sendmail[3636]: 089McFtJ003636: --- 250-PIPELINING
Sep 9 17:38:15 vps sendmail[3636]: 089McFtJ003636: --- 250-8BITMIME
Sep 9 17:38:15 vps sendmail[3636]: 089McFtJ003636: --- 250-SIZE
Sep 9 17:38:15 vps sendmail[3636]: 089McFtJ003636: --- 250-DSN
Sep 9 17:38:15 vps sendmail[3636]: 089McFtJ003636: --- 250-AUTH GSSAPI DIGEST-MD5 CRAM-MD5
Sep 9 17:38:15 vps sendmail[3636]: 089McFtJ003636: --- 250-STARTTLS
Sep 9 17:38:15 vps sendmail[3636]: 089McFtJ003636: --- 250-DELIVERBY
Sep 9 17:38:15 vps sendmail[3636]: 089McFtJ003636: --- 250 HELP
Sep 9 17:38:15 vps sendmail[3636]: 089McFtJ003636: <-- STARTTLS
Sep 9 17:38:15 vps sendmail[3636]: 089McFtJ003636: --- 220 2.0.0 Ready to start TLS
Sep 9 17:56:15 vps sendmail[3636]: STARTTLS: internal error: tls_verify_cb: ssl == NULL
Sep 9 17:56:15 vps sendmail[3636]: STARTTLS=server,info: fds=7/4,err=1
Sep 9 17:56:15 vps sendmail[3636]: STARTTLS=server,error: accept failed=0,reason=tlsv1 alert unknown ca,SSL_error=1,errno=0,retry=-1,relay=cpe-76-85-14-185.tx.res.rr.com [76.85.14.185]
Sep 9 17:56:15 vps sendmail[3636]: STARTTLS=server: 3636:error:14094418:SSL routines:ssl3_read_bytes:tlsv1 alert unknown ca:s3_pkt.c:1493:SSL alert number 48
现在这是从Java(OpenJDK 1.8 VM)客户端发送电子邮件时可以使用的日志。注意,“ AUTH DIGEST-MD5”不是从PHP SwiftMailer代码发送的。
Sep 9 18:14:17 vps sendmail[3669]: 089NEHWe003669: <-- EHLO vps.ezlista.com
Sep 9 18:14:17 vps sendmail[3669]: 089NEHWe003669: --- 250-vps.ezlista.com Hello vps.ezlista.com [69.10.46.173],pleased to meet you
Sep 9 18:14:17 vps sendmail[3669]: 089NEHWe003669: --- 250-ENHANCEDSTATUSCODES
Sep 9 18:14:17 vps sendmail[3669]: 089NEHWe003669: --- 250-PIPELINING
Sep 9 18:14:17 vps sendmail[3669]: 089NEHWe003669: --- 250-8BITMIME
Sep 9 18:14:17 vps sendmail[3669]: 089NEHWe003669: --- 250-SIZE
Sep 9 18:14:17 vps sendmail[3669]: 089NEHWe003669: --- 250-DSN
Sep 9 18:14:17 vps sendmail[3669]: 089NEHWe003669: --- 250-AUTH GSSAPI DIGEST-MD5 CRAM-MD5
Sep 9 18:14:17 vps sendmail[3669]: 089NEHWe003669: --- 250-STARTTLS
Sep 9 18:14:17 vps sendmail[3669]: 089NEHWe003669: --- 250-DELIVERBY
Sep 9 18:14:17 vps sendmail[3669]: 089NEHWe003669: --- 250 HELP
Sep 9 18:14:17 vps sendmail[3669]: 089NEHWe003669: <-- AUTH DIGEST-MD5
Sep 9 18:14:17 vps sendmail[3669]: 089NEHWe003669: --- 334 bm9uY2U9InBrVzFIRXRldWxGclltNk5RNjFJVmVvQzVzY0RsVmVPRHZYUHF3QzBBaVE9IixyZWFsbT0idnBzLmV6bGlzdGEuY29tIixxb3A9ImF1dGgsYXV0aC1pbnQsYXV0aC1jb25mIixjaXBoZXI9InJjNC00MCxyYzQtNTYscmM0LGRlcywzZGVzIixtYXhidWY9ODE5MixjaGFyc2V0PXV0Zi04LGFsZ29yaXRobT1tZDUtc2Vzcw==
Sep 9 18:14:17 vps sendmail[3669]: 089NEHWe003669: --- 334 cnNwYXV0aD0yYjUzYTMyMjk0MzA0MzA3MDVlMTM0OTU3NTFmODQyYg==
Sep 9 18:14:17 vps sendmail[3669]: 089NEHWe003669: --- 235 2.0.0 OK Authenticated
Sep 9 18:14:17 vps sendmail[3669]: AUTH=server,relay=vps.ezlista.com [69.10.46.173],authid=webmaster@ezlista.com,mech=DIGEST-MD5,bits=0
Sep 9 18:14:17 vps sendmail[3669]: 089NEHWe003669: <-- MAIL FROM:<webmaster@ezlista.com>
Sep 9 18:14:17 vps sendmail[3669]: 089NEHWe003669: --- 250 2.1.0 <webmaster@ezlista.com>... Sender ok
Sep 9 18:14:17 vps sendmail[3669]: 089NEHWe003669: <-- RCPT TO:<rubens_gomes@hotmail.com>
Sep 9 18:14:17 vps sendmail[3669]: 089NEHWe003669: --- 250 2.1.5 <rubens_gomes@hotmail.com>... Recipient ok
Sep 9 18:14:17 vps sendmail[3669]: 089NEHWe003669: <-- DATA
.....
....
预期的行为
电子邮件将通过PHP Swift_Mailer代码通过STARTLS /授权渠道发送。
示例
这是我正在使用的测试代码。这段代码是我的Laravel 7项目的一部分。
<?php
namespace Tests\Live;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Log;
use Tests\TestCase;
use Swift_Mailer;
use Swift_Message;
class SwiftMailerTest extends TestCase
{
private const TO_ADDR = 'rubens.s.gomes@gmail.com';
private const TO_NAME = 'Rubens Gomes';
/** @var $mailer \Swift_Mailer the mailer used to send emails */
private $mailer;
public function setUp(): void
{
parent::setUp();
// create transport
Log::debug('creating transport');
$host = Config::get('mail.mailers.smtp.host');
$port = Config::get('mail.mailers.smtp.port');
$encryption = Config::get('mail.mailers.smtp.encryption');
$transportData = [
'host' => $host,'port' => $port,'encryption' => $encryption
];
Log::debug('transport data',$transportData);
$transport = new \Swift_SmtpTransport($host,$port,$encryption);
// create mailer
Log::debug('creating mailer');
$username = Config::get('mail.mailers.smtp.username');
$password = Config::get('mail.mailers.smtp.password');
$mailerData = [
'username' => $username,'password' => $password
];
Log::debug('mailer data',$mailerData);
$transport->setUsername($username);
$transport->setPassword($password);
$this->mailer = new Swift_Mailer($transport);
}
public function tearDown(): void
{
parent::tearDown();
if(isset($this->mailer))
{
$this->mailer->getTransport()->stop();
}
}
public function testSendingMail(): void
{
// create message
Log::debug('creating message');
$subject = Config::get('mail.mailers.subject');
$message = new Swift_Message($subject);
$fromAddress = Config::get('mail.from.address');
$fromName = Config::get('mail.from.name');
$messageData = [
'subject' => $subject,'fromAddress' => $fromAddress,'fromName' => $fromName,'toAddress' => self::TO_ADDR,'toName' => self::TO_NAME
];
Log::debug('message data',$messageData);
$message->setFrom($fromAddress,$fromName);
$message->setTo(self::TO_ADDR,self::TO_NAME);
$message->setBody('Hello Mail');
// send mail
Log::debug('sending mail');
$status = $this->mailer->send($message);
$this->assertNotNull($status);
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)