Unfortunatly verify_peer feature is not in symfony 4.4 (yet) as @yivi states correctly.
I tried updating symfony/mailer in composer to dev-master but symfony flex constraints doesnt allow this due to:
Restricting packages listed in "symfony/symfony" to "4.4.*"
So i ended up overriding mailer.transport_factory.smtp
:
mailer.transport_factory.smtp:
class: App\Mailer\EsmtpTransportFactory
tags:
- { name: 'mailer.transport_factory', priority: "-100" }
with a custom EsmtpTransportFactory that contains this feature:
<?php
namespace App\Mailer;
use Symfony\Component\Mailer\Transport\AbstractTransportFactory;
use Symfony\Component\Mailer\Transport\Dsn;
use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport;
use Symfony\Component\Mailer\Transport\TransportInterface;
final class EsmtpTransportFactory extends AbstractTransportFactory
{
public function create(Dsn $dsn): TransportInterface
{
$tls = 'smtps' === $dsn->getScheme() ? true : null;
$port = $dsn->getPort(0);
$host = $dsn->getHost();
$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);
}
if ($password = $dsn->getPassword()) {
$transport->setPassword($password);
}
return $transport;
}
protected function getSupportedSchemes(): array
{
return ['smtp', 'smtps'];
}
}
Note the bool value if verify_peer in the DSN can't be a string.
This will not work: MAILER_DSN=smtp://foo@default?verify_peer=false
This will work: MAILER_DSN=smtp://foo@default?verify_peer=0
or as mentioned in this comment:
parameters:
env(verify): 'false'
framework:
mailer:
dsn: '%env(MAILER_DSN)%?verify_peer=%env(bool:verify)%'
I guess it would be better if this feature was ported to 4.4 but so long i use this workaround.