Skip to content

Commit 2b8b386

Browse files
authored
Revert "set schema to smtps if MAIL_ENCRYPTION === tls" (#53863)
* Revert "adjust MailManager to detect if smtp or smtps is needed by checking e…" This reverts commit c07f426. * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * Update comment Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> --------- Signed-off-by: Mior Muhammad Zaki <[email protected]>
1 parent b9df1f7 commit 2b8b386

File tree

2 files changed

+66
-3
lines changed

2 files changed

+66
-3
lines changed

src/Illuminate/Mail/MailManager.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,7 @@ protected function createSmtpTransport(array $config)
194194
$scheme = $config['scheme'] ?? null;
195195

196196
if (! $scheme) {
197-
$scheme = ! empty($config['encryption']) && $config['encryption'] === 'tls'
198-
? 'smtps'
199-
: 'smtp';
197+
$scheme = ($config['port'] == 465) ? 'smtps' : 'smtp';
200198
}
201199

202200
$transport = $factory->create(new Dsn(

tests/Mail/MailManagerTest.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,71 @@ public function testMailUrlConfig($scheme, $port)
5050
$this->assertSame('127.0.0.2', $transport->getStream()->getHost());
5151
$this->assertSame($port, $transport->getStream()->getPort());
5252
$this->assertSame($port === 465, $transport->getStream()->isTLS());
53+
54+
if (method_exists($transport, 'isAutoTls')) {
55+
// Only available from Symfony Mailer 7.1
56+
$this->assertTrue($transport->isAutoTls());
57+
}
58+
}
59+
60+
#[TestWith([null, 5876])]
61+
#[TestWith([null, 465])]
62+
#[TestWith(['smtp', 25])]
63+
#[TestWith(['smtp', 2525])]
64+
#[TestWith(['smtps', 465])]
65+
#[TestWith(['smtp', 465])]
66+
public function testMailUrlConfigWithAutoTls($scheme, $port)
67+
{
68+
$this->app['config']->set('mail.mailers.smtp_url', [
69+
'scheme' => $scheme,
70+
'url' => "smtp://usr:[email protected]:{$port}?auto_tls=true",
71+
]);
72+
73+
$mailer = $this->app['mail.manager']->mailer('smtp_url');
74+
$transport = $mailer->getSymfonyTransport();
75+
76+
$this->assertInstanceOf(EsmtpTransport::class, $transport);
77+
$this->assertSame('usr', $transport->getUsername());
78+
$this->assertSame('pwd', $transport->getPassword());
79+
$this->assertSame('127.0.0.2', $transport->getStream()->getHost());
80+
$this->assertSame($port, $transport->getStream()->getPort());
81+
$this->assertSame($port === 465, $transport->getStream()->isTLS());
82+
83+
if (method_exists($transport, 'isAutoTls')) {
84+
// Only available from Symfony Mailer 7.1
85+
$this->assertTrue($transport->isAutoTls());
86+
}
87+
}
88+
89+
#[TestWith([null, 5876])]
90+
#[TestWith([null, 465])]
91+
#[TestWith(['smtp', 25])]
92+
#[TestWith(['smtp', 2525])]
93+
#[TestWith(['smtps', 465])]
94+
#[TestWith(['smtp', 465])]
95+
public function testMailUrlConfigWithAutoTlsDisabled($scheme, $port)
96+
{
97+
$this->app['config']->set('mail.mailers.smtp_url', [
98+
'scheme' => $scheme,
99+
'url' => "smtp://usr:[email protected]:{$port}?auto_tls=false",
100+
]);
101+
102+
$mailer = $this->app['mail.manager']->mailer('smtp_url');
103+
$transport = $mailer->getSymfonyTransport();
104+
105+
$this->assertInstanceOf(EsmtpTransport::class, $transport);
106+
$this->assertSame('usr', $transport->getUsername());
107+
$this->assertSame('pwd', $transport->getPassword());
108+
$this->assertSame('127.0.0.2', $transport->getStream()->getHost());
109+
$this->assertSame($port, $transport->getStream()->getPort());
110+
111+
if (method_exists($transport, 'isAutoTls')) {
112+
// Only available from Symfony Mailer 7.1
113+
$this->assertFalse($transport->isAutoTls());
114+
$this->assertSame($port === 465 && $scheme !== 'smtp', $transport->getStream()->isTLS());
115+
} else {
116+
$this->assertSame($port === 465, $transport->getStream()->isTLS());
117+
}
53118
}
54119

55120
public function testBuild()

0 commit comments

Comments
 (0)