From 665d1cd3fa9638b655f032a8b8658bc6c3b4e305 Mon Sep 17 00:00:00 2001 From: Fritz Michael Gschwantner Date: Fri, 26 Jun 2020 21:31:47 +0100 Subject: [PATCH] [Mailer] Implement additional mailer transport options --- src/Symfony/Component/Mailer/CHANGELOG.md | 2 ++ .../SendmailTransportFactoryTest.php | 5 ++++ .../Smtp/EsmtpTransportFactoryTest.php | 24 +++++++++++++++++++ .../Transport/SendmailTransportFactory.php | 2 +- .../Transport/Smtp/EsmtpTransportFactory.php | 12 ++++++++++ 5 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Mailer/CHANGELOG.md b/src/Symfony/Component/Mailer/CHANGELOG.md index e36f282dfd..cca04f11aa 100644 --- a/src/Symfony/Component/Mailer/CHANGELOG.md +++ b/src/Symfony/Component/Mailer/CHANGELOG.md @@ -5,6 +5,8 @@ CHANGELOG ----- * added `NativeTransportFactory` to configure a transport based on php.ini settings + * added `local_domain`, `restart_threshold`, `restart_threshold_sleep` and `ping_threshold` options for `smtp` + * added `command` option for `sendmail` 4.4.0 ----- diff --git a/src/Symfony/Component/Mailer/Tests/Transport/SendmailTransportFactoryTest.php b/src/Symfony/Component/Mailer/Tests/Transport/SendmailTransportFactoryTest.php index 1898e143d5..55f893b0ad 100644 --- a/src/Symfony/Component/Mailer/Tests/Transport/SendmailTransportFactoryTest.php +++ b/src/Symfony/Component/Mailer/Tests/Transport/SendmailTransportFactoryTest.php @@ -38,6 +38,11 @@ class SendmailTransportFactoryTest extends TransportFactoryTestCase new Dsn('sendmail+smtp', 'default'), new SendmailTransport(null, $this->getDispatcher(), $this->getLogger()), ]; + + yield [ + new Dsn('sendmail+smtp', 'default', null, null, null, ['command' => '/usr/sbin/sendmail -oi -t']), + new SendmailTransport('/usr/sbin/sendmail -oi -t', $this->getDispatcher(), $this->getLogger()), + ]; } public function unsupportedSchemeProvider(): iterable diff --git a/src/Symfony/Component/Mailer/Tests/Transport/Smtp/EsmtpTransportFactoryTest.php b/src/Symfony/Component/Mailer/Tests/Transport/Smtp/EsmtpTransportFactoryTest.php index cd410f89cc..b248235c87 100644 --- a/src/Symfony/Component/Mailer/Tests/Transport/Smtp/EsmtpTransportFactoryTest.php +++ b/src/Symfony/Component/Mailer/Tests/Transport/Smtp/EsmtpTransportFactoryTest.php @@ -81,5 +81,29 @@ class EsmtpTransportFactoryTest extends TransportFactoryTestCase new Dsn('smtps', 'example.com', '', '', 465, ['verify_peer' => false]), $transport, ]; + + $transport = new EsmtpTransport('example.com', 465, true, $eventDispatcher, $logger); + $transport->setLocalDomain('example.com'); + + yield [ + new Dsn('smtps', 'example.com', '', '', 465, ['local_domain' => 'example.com']), + $transport, + ]; + + $transport = new EsmtpTransport('example.com', 465, true, $eventDispatcher, $logger); + $transport->setRestartThreshold(10, 1); + + yield [ + new Dsn('smtps', 'example.com', '', '', 465, ['restart_threshold' => '10', 'restart_threshold_sleep' => '1']), + $transport, + ]; + + $transport = new EsmtpTransport('example.com', 465, true, $eventDispatcher, $logger); + $transport->setPingThreshold(10); + + yield [ + new Dsn('smtps', 'example.com', '', '', 465, ['ping_threshold' => '10']), + $transport, + ]; } } diff --git a/src/Symfony/Component/Mailer/Transport/SendmailTransportFactory.php b/src/Symfony/Component/Mailer/Transport/SendmailTransportFactory.php index 77d6d49a4a..6d977e74b7 100644 --- a/src/Symfony/Component/Mailer/Transport/SendmailTransportFactory.php +++ b/src/Symfony/Component/Mailer/Transport/SendmailTransportFactory.php @@ -21,7 +21,7 @@ final class SendmailTransportFactory extends AbstractTransportFactory public function create(Dsn $dsn): TransportInterface { if ('sendmail+smtp' === $dsn->getScheme() || 'sendmail' === $dsn->getScheme()) { - return new SendmailTransport(null, $this->dispatcher, $this->logger); + return new SendmailTransport($dsn->getOption('command'), $this->dispatcher, $this->logger); } throw new UnsupportedSchemeException($dsn, 'sendmail', $this->getSupportedSchemes()); diff --git a/src/Symfony/Component/Mailer/Transport/Smtp/EsmtpTransportFactory.php b/src/Symfony/Component/Mailer/Transport/Smtp/EsmtpTransportFactory.php index e09963652b..f3b912a204 100644 --- a/src/Symfony/Component/Mailer/Transport/Smtp/EsmtpTransportFactory.php +++ b/src/Symfony/Component/Mailer/Transport/Smtp/EsmtpTransportFactory.php @@ -48,6 +48,18 @@ final class EsmtpTransportFactory extends AbstractTransportFactory $transport->setPassword($password); } + if (null !== ($localDomain = $dsn->getOption('local_domain'))) { + $transport->setLocalDomain($localDomain); + } + + if (null !== ($restartThreshold = $dsn->getOption('restart_threshold'))) { + $transport->setRestartThreshold((int) $restartThreshold, (int) $dsn->getOption('restart_threshold_sleep', 0)); + } + + if (null !== ($pingThreshold = $dsn->getOption('ping_threshold'))) { + $transport->setPingThreshold((int) $pingThreshold); + } + return $transport; }