Skip to content

Commit

Permalink
Revert "set schema to smtps if MAIL_ENCRYPTION === tls" (#53863)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
crynobone authored Dec 12, 2024
1 parent b9df1f7 commit 2b8b386
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/Illuminate/Mail/MailManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,7 @@ protected function createSmtpTransport(array $config)
$scheme = $config['scheme'] ?? null;

if (! $scheme) {
$scheme = ! empty($config['encryption']) && $config['encryption'] === 'tls'
? 'smtps'
: 'smtp';
$scheme = ($config['port'] == 465) ? 'smtps' : 'smtp';
}

$transport = $factory->create(new Dsn(
Expand Down
65 changes: 65 additions & 0 deletions tests/Mail/MailManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,71 @@ public function testMailUrlConfig($scheme, $port)
$this->assertSame('127.0.0.2', $transport->getStream()->getHost());
$this->assertSame($port, $transport->getStream()->getPort());
$this->assertSame($port === 465, $transport->getStream()->isTLS());

if (method_exists($transport, 'isAutoTls')) {
// Only available from Symfony Mailer 7.1
$this->assertTrue($transport->isAutoTls());
}
}

#[TestWith([null, 5876])]
#[TestWith([null, 465])]
#[TestWith(['smtp', 25])]
#[TestWith(['smtp', 2525])]
#[TestWith(['smtps', 465])]
#[TestWith(['smtp', 465])]
public function testMailUrlConfigWithAutoTls($scheme, $port)
{
$this->app['config']->set('mail.mailers.smtp_url', [
'scheme' => $scheme,
'url' => "smtp://usr:[email protected]:{$port}?auto_tls=true",
]);

$mailer = $this->app['mail.manager']->mailer('smtp_url');
$transport = $mailer->getSymfonyTransport();

$this->assertInstanceOf(EsmtpTransport::class, $transport);
$this->assertSame('usr', $transport->getUsername());
$this->assertSame('pwd', $transport->getPassword());
$this->assertSame('127.0.0.2', $transport->getStream()->getHost());
$this->assertSame($port, $transport->getStream()->getPort());
$this->assertSame($port === 465, $transport->getStream()->isTLS());

if (method_exists($transport, 'isAutoTls')) {
// Only available from Symfony Mailer 7.1
$this->assertTrue($transport->isAutoTls());
}
}

#[TestWith([null, 5876])]
#[TestWith([null, 465])]
#[TestWith(['smtp', 25])]
#[TestWith(['smtp', 2525])]
#[TestWith(['smtps', 465])]
#[TestWith(['smtp', 465])]
public function testMailUrlConfigWithAutoTlsDisabled($scheme, $port)
{
$this->app['config']->set('mail.mailers.smtp_url', [
'scheme' => $scheme,
'url' => "smtp://usr:[email protected]:{$port}?auto_tls=false",
]);

$mailer = $this->app['mail.manager']->mailer('smtp_url');
$transport = $mailer->getSymfonyTransport();

$this->assertInstanceOf(EsmtpTransport::class, $transport);
$this->assertSame('usr', $transport->getUsername());
$this->assertSame('pwd', $transport->getPassword());
$this->assertSame('127.0.0.2', $transport->getStream()->getHost());
$this->assertSame($port, $transport->getStream()->getPort());

if (method_exists($transport, 'isAutoTls')) {
// Only available from Symfony Mailer 7.1
$this->assertFalse($transport->isAutoTls());
$this->assertSame($port === 465 && $scheme !== 'smtp', $transport->getStream()->isTLS());
} else {
$this->assertSame($port === 465, $transport->getStream()->isTLS());
}
}

public function testBuild()
Expand Down

0 comments on commit 2b8b386

Please sign in to comment.