[Mailer] add ability to disable the TLS peer verification via DSN
This commit is contained in:
parent
20bf17f6ad
commit
4b854da73e
@ -36,6 +36,7 @@ CHANGELOG
|
||||
* Added `Symfony\Component\Mailer\Test\TransportFactoryTestCase` to ease testing custom transport factories.
|
||||
* Added `SentMessage::getDebug()` and `TransportExceptionInterface::getDebug` to help debugging
|
||||
* Made `MessageEvent` final
|
||||
* add DSN parameter `verify_peer` to disable TLS peer verification for SMTP transport
|
||||
|
||||
4.3.0
|
||||
-----
|
||||
|
@ -6,6 +6,7 @@ use Symfony\Component\Mailer\Test\TransportFactoryTestCase;
|
||||
use Symfony\Component\Mailer\Transport\Dsn;
|
||||
use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport;
|
||||
use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransportFactory;
|
||||
use Symfony\Component\Mailer\Transport\Smtp\Stream\SocketStream;
|
||||
use Symfony\Component\Mailer\Transport\TransportFactoryInterface;
|
||||
|
||||
class EsmtpTransportFactoryTest extends TransportFactoryTestCase
|
||||
@ -67,5 +68,18 @@ class EsmtpTransportFactoryTest extends TransportFactoryTestCase
|
||||
new Dsn('smtps', 'example.com', '', '', 465),
|
||||
$transport,
|
||||
];
|
||||
|
||||
$transport = new EsmtpTransport('example.com', 465, true, $eventDispatcher, $logger);
|
||||
/** @var SocketStream $stream */
|
||||
$stream = $transport->getStream();
|
||||
$streamOptions = $stream->getStreamOptions();
|
||||
$streamOptions['ssl']['verify_peer'] = false;
|
||||
$streamOptions['ssl']['verify_peer_name'] = false;
|
||||
$stream->setStreamOptions($streamOptions);
|
||||
|
||||
yield [
|
||||
new Dsn('smtps', 'example.com', '', '', 465, ['verify_peer' => false]),
|
||||
$transport,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ namespace Symfony\Component\Mailer\Transport\Smtp;
|
||||
|
||||
use Symfony\Component\Mailer\Transport\AbstractTransportFactory;
|
||||
use Symfony\Component\Mailer\Transport\Dsn;
|
||||
use Symfony\Component\Mailer\Transport\Smtp\Stream\SocketStream;
|
||||
use Symfony\Component\Mailer\Transport\TransportInterface;
|
||||
|
||||
/**
|
||||
@ -28,6 +29,17 @@ final class EsmtpTransportFactory extends AbstractTransportFactory
|
||||
|
||||
$transport = new EsmtpTransport($host, $port, $tls, $this->dispatcher, $this->logger);
|
||||
|
||||
if (!$dsn->getOption('verify_peer', true)) {
|
||||
/** @var SocketStream $stream */
|
||||
$stream = $transport->getStream();
|
||||
$streamOptions = $stream->getStreamOptions();
|
||||
|
||||
$streamOptions['ssl']['verify_peer'] = false;
|
||||
$streamOptions['ssl']['verify_peer_name'] = false;
|
||||
|
||||
$stream->setStreamOptions($streamOptions);
|
||||
}
|
||||
|
||||
if ($user = $dsn->getUser()) {
|
||||
$transport->setUsername($user);
|
||||
}
|
||||
|
Reference in New Issue
Block a user