| 148 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
* This file is part of the Symfony package.
|
|
|
5 |
*
|
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
7 |
*
|
|
|
8 |
* For the full copyright and license information, please view the LICENSE
|
|
|
9 |
* file that was distributed with this source code.
|
|
|
10 |
*/
|
|
|
11 |
|
|
|
12 |
namespace Symfony\Component\Mailer\Transport\Smtp;
|
|
|
13 |
|
|
|
14 |
use Symfony\Component\Mailer\Transport\AbstractTransportFactory;
|
|
|
15 |
use Symfony\Component\Mailer\Transport\Dsn;
|
|
|
16 |
use Symfony\Component\Mailer\Transport\Smtp\Stream\SocketStream;
|
|
|
17 |
use Symfony\Component\Mailer\Transport\TransportInterface;
|
|
|
18 |
|
|
|
19 |
/**
|
|
|
20 |
* @author Konstantin Myakshin <molodchick@gmail.com>
|
|
|
21 |
*/
|
|
|
22 |
final class EsmtpTransportFactory extends AbstractTransportFactory
|
|
|
23 |
{
|
|
|
24 |
public function create(Dsn $dsn): TransportInterface
|
|
|
25 |
{
|
|
|
26 |
$tls = 'smtps' === $dsn->getScheme() ? true : null;
|
|
|
27 |
$port = $dsn->getPort(0);
|
|
|
28 |
$host = $dsn->getHost();
|
|
|
29 |
|
|
|
30 |
$transport = new EsmtpTransport($host, $port, $tls, $this->dispatcher, $this->logger);
|
|
|
31 |
|
|
|
32 |
if ('' !== $dsn->getOption('verify_peer') && !filter_var($dsn->getOption('verify_peer', true), \FILTER_VALIDATE_BOOL)) {
|
|
|
33 |
/** @var SocketStream $stream */
|
|
|
34 |
$stream = $transport->getStream();
|
|
|
35 |
$streamOptions = $stream->getStreamOptions();
|
|
|
36 |
|
|
|
37 |
$streamOptions['ssl']['verify_peer'] = false;
|
|
|
38 |
$streamOptions['ssl']['verify_peer_name'] = false;
|
|
|
39 |
|
|
|
40 |
$stream->setStreamOptions($streamOptions);
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
if ($user = $dsn->getUser()) {
|
|
|
44 |
$transport->setUsername($user);
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
if ($password = $dsn->getPassword()) {
|
|
|
48 |
$transport->setPassword($password);
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
if (null !== ($localDomain = $dsn->getOption('local_domain'))) {
|
|
|
52 |
$transport->setLocalDomain($localDomain);
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
if (null !== ($maxPerSecond = $dsn->getOption('max_per_second'))) {
|
|
|
56 |
$transport->setMaxPerSecond((float) $maxPerSecond);
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
if (null !== ($restartThreshold = $dsn->getOption('restart_threshold'))) {
|
|
|
60 |
$transport->setRestartThreshold((int) $restartThreshold, (int) $dsn->getOption('restart_threshold_sleep', 0));
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
if (null !== ($pingThreshold = $dsn->getOption('ping_threshold'))) {
|
|
|
64 |
$transport->setPingThreshold((int) $pingThreshold);
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
return $transport;
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
protected function getSupportedSchemes(): array
|
|
|
71 |
{
|
|
|
72 |
return ['smtp', 'smtps'];
|
|
|
73 |
}
|
|
|
74 |
}
|