Skip to content

[Mailer] [Smtp] Add DSN option to make SocketStream bind to IPv4 #59482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Symfony/Component/Mailer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ CHANGELOG

* Add DSN param `retry_period` to override default email transport retry period
* Add `Dsn::getBooleanOption()`
* Add DSN param `source_ip` to allow binding to a (specific) IPv4 or IPv6 address.

7.2
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,20 @@ public static function createProvider(): iterable
Dsn::fromString('smtp://:@example.com:465?auto_tls=false'),
$transport,
];

$transport = new EsmtpTransport('example.com', 465, true, null, $logger);
$transport->getStream()->setSourceIp('0.0.0.0');
yield [
Dsn::fromString('smtps://:@example.com:465?source_ip=0.0.0.0'),
$transport,
];

$transport = new EsmtpTransport('example.com', 465, true, null, $logger);
$transport->getStream()->setSourceIp('[2606:4700:20::681a:5fb]');
yield [
Dsn::fromString('smtps://:@example.com:465?source_ip=[2606:4700:20::681a:5fb]'),
$transport,
];
}

public static function unsupportedSchemeProvider(): iterable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public function create(Dsn $dsn): TransportInterface

/** @var SocketStream $stream */
$stream = $transport->getStream();
if ('' !== $sourceIp = $dsn->getOption('source_ip', '')) {
$stream->setSourceIp($sourceIp);
}
$streamOptions = $stream->getStreamOptions();

if ('' !== $dsn->getOption('verify_peer') && !filter_var($dsn->getOption('verify_peer', true), \FILTER_VALIDATE_BOOL)) {
Expand Down