Skip to content

Commit ba98fd7

Browse files
committed
feature #37432 [Mailer] Implement additional mailer transport options (fritzmg)
This PR was squashed before being merged into the 5.2-dev branch. Discussion ---------- [Mailer] Implement additional mailer transport options | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Fix #37300 | License | MIT | Doc PR | symfony/symfony-docs#13911 This implements additional transport configuration options mentioned in #37300. It also adds a `command` option to be able to define the command used by the `sendmail` transport. Examples: ```yml framework: mailer: transports: sendmail: sendmail://default?command=/usr/sbin/sendmail%%20-oi%%20-t local_domain: smtps://smtp.example.com?local_domain=example.org restart_threshold: smtps://smtp.example.com?restart_threshold=10&restart_threshold_sleep=1 ping_threshold: smtps://smtp.example.com?ping_threshold=200 ``` Commits ------- 665d1cd [Mailer] Implement additional mailer transport options
2 parents df84e22 + 665d1cd commit ba98fd7

File tree

5 files changed

+44
-1
lines changed

5 files changed

+44
-1
lines changed

src/Symfony/Component/Mailer/CHANGELOG.md

+2
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

+5
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

+24
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

+1-1
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

+12
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)