Skip to content

Commit 665d1cd

Browse files
fritzmgfabpot
authored andcommitted
[Mailer] Implement additional mailer transport options
1 parent 6d521d4 commit 665d1cd

File tree

5 files changed

+44
-1
lines changed

5 files changed

+44
-1
lines changed

src/Symfony/Component/Mailer/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ CHANGELOG
55
-----
66

77
* added `NativeTransportFactory` to configure a transport based on php.ini settings
8+
* added `local_domain`, `restart_threshold`, `restart_threshold_sleep` and `ping_threshold` options for `smtp`
9+
* added `command` option for `sendmail`
810

911
4.4.0
1012
-----

src/Symfony/Component/Mailer/Tests/Transport/SendmailTransportFactoryTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ public function createProvider(): iterable
3838
new Dsn('sendmail+smtp', 'default'),
3939
new SendmailTransport(null, $this->getDispatcher(), $this->getLogger()),
4040
];
41+
42+
yield [
43+
new Dsn('sendmail+smtp', 'default', null, null, null, ['command' => '/usr/sbin/sendmail -oi -t']),
44+
new SendmailTransport('/usr/sbin/sendmail -oi -t', $this->getDispatcher(), $this->getLogger()),
45+
];
4146
}
4247

4348
public function unsupportedSchemeProvider(): iterable

src/Symfony/Component/Mailer/Tests/Transport/Smtp/EsmtpTransportFactoryTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,29 @@ public function createProvider(): iterable
8181
new Dsn('smtps', 'example.com', '', '', 465, ['verify_peer' => false]),
8282
$transport,
8383
];
84+
85+
$transport = new EsmtpTransport('example.com', 465, true, $eventDispatcher, $logger);
86+
$transport->setLocalDomain('example.com');
87+
88+
yield [
89+
new Dsn('smtps', 'example.com', '', '', 465, ['local_domain' => 'example.com']),
90+
$transport,
91+
];
92+
93+
$transport = new EsmtpTransport('example.com', 465, true, $eventDispatcher, $logger);
94+
$transport->setRestartThreshold(10, 1);
95+
96+
yield [
97+
new Dsn('smtps', 'example.com', '', '', 465, ['restart_threshold' => '10', 'restart_threshold_sleep' => '1']),
98+
$transport,
99+
];
100+
101+
$transport = new EsmtpTransport('example.com', 465, true, $eventDispatcher, $logger);
102+
$transport->setPingThreshold(10);
103+
104+
yield [
105+
new Dsn('smtps', 'example.com', '', '', 465, ['ping_threshold' => '10']),
106+
$transport,
107+
];
84108
}
85109
}

src/Symfony/Component/Mailer/Transport/SendmailTransportFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ final class SendmailTransportFactory extends AbstractTransportFactory
2121
public function create(Dsn $dsn): TransportInterface
2222
{
2323
if ('sendmail+smtp' === $dsn->getScheme() || 'sendmail' === $dsn->getScheme()) {
24-
return new SendmailTransport(null, $this->dispatcher, $this->logger);
24+
return new SendmailTransport($dsn->getOption('command'), $this->dispatcher, $this->logger);
2525
}
2626

2727
throw new UnsupportedSchemeException($dsn, 'sendmail', $this->getSupportedSchemes());

src/Symfony/Component/Mailer/Transport/Smtp/EsmtpTransportFactory.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ public function create(Dsn $dsn): TransportInterface
4848
$transport->setPassword($password);
4949
}
5050

51+
if (null !== ($localDomain = $dsn->getOption('local_domain'))) {
52+
$transport->setLocalDomain($localDomain);
53+
}
54+
55+
if (null !== ($restartThreshold = $dsn->getOption('restart_threshold'))) {
56+
$transport->setRestartThreshold((int) $restartThreshold, (int) $dsn->getOption('restart_threshold_sleep', 0));
57+
}
58+
59+
if (null !== ($pingThreshold = $dsn->getOption('ping_threshold'))) {
60+
$transport->setPingThreshold((int) $pingThreshold);
61+
}
62+
5163
return $transport;
5264
}
5365

0 commit comments

Comments
 (0)