Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit5091cd5

Browse files
feature#53621 [Mailer] [Smtp] Add DSN param 'auto_tls' to disable automatic STARTTLS (srsbiz)
This PR was squashed before being merged into the 7.1 branch.Discussion----------[Mailer] [Smtp] Add DSN param 'auto_tls' to disable automatic STARTTLS| Q | A| ------------- | ---| Branch? | 7.1| Bug fix? | no| New feature? | yes| Deprecations? | no| Issues |Fix#49114| License | MITMany times we don't have any jurisdiction over configuration of SMTP server we are trying to connect to. If such server claims to be capable of STARTTLS, but drops connection after sending this command, there was no way to prevent mailer from sending it - despite defining protocol as `stmp` and port `25`.Now adding `auto_tls=false` to DSN we can prevent transport to automatically send STARTTLS when we do not intend to use TLS.Commits-------189a1ac [Mailer] [Smtp] Add DSN param 'auto_tls' to disable automatic STARTTLS
2 parentse00c12e +189a1ac commit5091cd5

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Dispatch Postmark's "406 - Inactive recipient" API error code as a`PostmarkDeliveryEvent` instead of throwing an exception
8+
* Add DSN param`auto_tls` to disable automatic STARTTLS
89

910
7.0
1011
---

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,5 +157,28 @@ public static function createProvider(): iterable
157157
newDsn('smtps','example.com','','',465, ['ping_threshold' =>'10']),
158158
$transport,
159159
];
160+
161+
$transport =newEsmtpTransport('example.com',25,false,null,$logger);
162+
$transport->setAutoTls(false);
163+
164+
yield [
165+
newDsn('smtp','example.com','','',25, ['auto_tls' =>false]),
166+
$transport,
167+
];
168+
yield [
169+
newDsn('smtp','example.com','','',0, ['auto_tls' =>false]),
170+
$transport,
171+
];
172+
yield [
173+
Dsn::fromString('smtp://:@example.com?auto_tls=false'),
174+
$transport,
175+
];
176+
177+
$transport =newEsmtpTransport('example.com',465,false,null,$logger);
178+
$transport->setAutoTls(false);
179+
yield [
180+
Dsn::fromString('smtp://:@example.com:465?auto_tls=false'),
181+
$transport,
182+
];
160183
}
161184
}

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class EsmtpTransport extends SmtpTransport
3131
privatestring$username ='';
3232
privatestring$password ='';
3333
privatearray$capabilities;
34+
privatebool$autoTls =true;
3435

3536
publicfunction__construct(string$host ='localhost',int$port =0, ?bool$tls =null, ?EventDispatcherInterface$dispatcher =null, ?LoggerInterface$logger =null, ?AbstractStream$stream =null, ?array$authenticators =null)
3637
{
@@ -99,6 +100,21 @@ public function getPassword(): string
99100
return$this->password;
100101
}
101102

103+
/**
104+
* @return $this
105+
*/
106+
publicfunctionsetAutoTls(bool$autoTls):static
107+
{
108+
$this->autoTls =$autoTls;
109+
110+
return$this;
111+
}
112+
113+
publicfunctionisAutoTls():bool
114+
{
115+
return$this->autoTls;
116+
}
117+
102118
publicfunctionsetAuthenticators(array$authenticators):void
103119
{
104120
$this->authenticators = [];
@@ -145,7 +161,7 @@ private function doEhloCommand(): string
145161
// WARNING: !$stream->isTLS() is right, 100% sure :)
146162
// if you think that the ! should be removed, read the code again
147163
// if doing so "fixes" your issue then it probably means your SMTP server behaves incorrectly or is wrongly configured
148-
if (!$stream->isTLS() &&\defined('OPENSSL_VERSION_NUMBER') &&\array_key_exists('STARTTLS',$this->capabilities)) {
164+
if ($this->autoTls &&!$stream->isTLS() &&\defined('OPENSSL_VERSION_NUMBER') &&\array_key_exists('STARTTLS',$this->capabilities)) {
149165
$this->executeCommand("STARTTLS\r\n", [220]);
150166

151167
if (!$stream->startTLS()) {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ final class EsmtpTransportFactory extends AbstractTransportFactory
2323
{
2424
publicfunctioncreate(Dsn$dsn):TransportInterface
2525
{
26-
$tls ='smtps' ===$dsn->getScheme() ?true :null;
26+
$autoTls ='' ===$dsn->getOption('auto_tls') ||filter_var($dsn->getOption('auto_tls',true), \FILTER_VALIDATE_BOOL);
27+
$tls ='smtps' ===$dsn->getScheme() ?true : ($autoTls ?null :false);
2728
$port =$dsn->getPort(0);
2829
$host =$dsn->getHost();
2930

3031
$transport =newEsmtpTransport($host,$port,$tls,$this->dispatcher,$this->logger);
32+
$transport->setAutoTls($autoTls);
3133

3234
/** @var SocketStream $stream */
3335
$stream =$transport->getStream();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp