Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 100d478

Browse filesBrowse files
committed
[Mailer] [Smtp] Add DSN option to make SocketStream bind to IPv4
1 parent dfcc142 commit 100d478
Copy full SHA for 100d478

File tree

4 files changed

+33
-0
lines changed
Filter options

4 files changed

+33
-0
lines changed

‎src/Symfony/Component/Mailer/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Add DSN param `retry_period` to override default email transport retry period
8+
* Add DSN param `force_ipv4` to enforce binding to IPv4
89

910
7.2
1011
---

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Tests/Transport/Smtp/EsmtpTransportFactoryTest.php
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,26 @@ public static function createProvider(): iterable
180180
Dsn::fromString('smtp://:@example.com:465?auto_tls=false'),
181181
$transport,
182182
];
183+
184+
$transport = new EsmtpTransport('example.com', 465, true, null, $logger);
185+
$transport->forceIpv4();
186+
yield [
187+
Dsn::fromString('smtps://:@example.com:465?force_ipv4=true'),
188+
$transport,
189+
];
190+
191+
$transport = new EsmtpTransport('example.com', 465, true, null, $logger);
192+
$transport->forceIpv4();
193+
yield [
194+
Dsn::fromString('smtps://:@example.com:465?force_ipv4'),
195+
$transport,
196+
];
197+
198+
$transport = new EsmtpTransport('example.com', 465, true, null, $logger);
199+
yield [
200+
Dsn::fromString('smtps://:@example.com:465?force_ipv4=false'),
201+
$transport,
202+
];
183203
}
184204

185205
public static function unsupportedSchemeProvider(): iterable

‎src/Symfony/Component/Mailer/Transport/Smtp/EsmtpTransport.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Transport/Smtp/EsmtpTransport.php
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ public function __construct(string $host = 'localhost', int $port = 0, ?bool $tl
7171
$stream->setPort($port);
7272
}
7373

74+
public function forceIpv4(): void
75+
{
76+
$stream = $this->getStream();
77+
if ($stream instanceof SocketStream) {
78+
$stream->setSourceIp('0.0.0.0');
79+
}
80+
}
81+
7482
/**
7583
* @return $this
7684
*/

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Transport/Smtp/EsmtpTransportFactory.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@ public function create(Dsn $dsn): TransportInterface
3232
$tls = 'smtps' === $dsn->getScheme() ? true : ($autoTls ? null : false);
3333
$port = $dsn->getPort(0);
3434
$host = $dsn->getHost();
35+
$forceIpv4 = '' === $dsn->getOption('force_ipv4') || filter_var($dsn->getOption('force_ipv4', false), \FILTER_VALIDATE_BOOL);
3536

3637
$transport = new EsmtpTransport($host, $port, $tls, $this->dispatcher, $this->logger);
3738
$transport->setAutoTls($autoTls);
39+
if ($forceIpv4) {
40+
$transport->forceIpv4();
41+
}
3842

3943
/** @var SocketStream $stream */
4044
$stream = $transport->getStream();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.