[Mailer] Implement additional mailer transport options

This commit is contained in:
Fritz Michael Gschwantner 2020-06-26 21:31:47 +01:00 committed by Fabien Potencier
parent 6d521d4072
commit 665d1cd3fa
5 changed files with 44 additions and 1 deletions

View File

@ -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
-----

View File

@ -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

View File

@ -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,
];
}
}

View File

@ -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());

View File

@ -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;
}