Skip to content

Commit 07a5e09

Browse files
[10.x] Add url support for mail config (#46964)
* Add url support for mail config * ci fix * formatting --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 1e6b467 commit 07a5e09

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/Illuminate/Mail/MailManager.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Illuminate\Mail\Transport\SesTransport;
1313
use Illuminate\Mail\Transport\SesV2Transport;
1414
use Illuminate\Support\Arr;
15+
use Illuminate\Support\ConfigurationUrlParser;
1516
use Illuminate\Support\Str;
1617
use InvalidArgumentException;
1718
use Psr\Log\LoggerInterface;
@@ -446,9 +447,17 @@ protected function getConfig(string $name)
446447
// Here we will check if the "driver" key exists and if it does we will use
447448
// the entire mail configuration file as the "driver" config in order to
448449
// provide "BC" for any Laravel <= 6.x style mail configuration files.
449-
return $this->app['config']['mail.driver']
450+
$config = $this->app['config']['mail.driver']
450451
? $this->app['config']['mail']
451452
: $this->app['config']["mail.mailers.{$name}"];
453+
454+
if (isset($config['url'])) {
455+
$config = array_merge($config, (new ConfigurationUrlParser)->parseConfiguration($config));
456+
457+
$config['transport'] = Arr::pull($config, 'driver');
458+
}
459+
460+
return $config;
452461
}
453462

454463
/**

tests/Mail/MailManagerTest.php

+17
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use InvalidArgumentException;
66
use Orchestra\Testbench\TestCase;
7+
use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport;
78

89
class MailManagerTest extends TestCase
910
{
@@ -27,6 +28,22 @@ public function testEmptyTransportConfig($transport)
2728
$this->app['mail.manager']->mailer('custom_smtp');
2829
}
2930

31+
public function testMailUrlConfig()
32+
{
33+
$this->app['config']->set('mail.mailers.smtp_url', [
34+
'url' => 'smtp://usr:[email protected]:5876',
35+
]);
36+
37+
$mailer = $this->app['mail.manager']->mailer('smtp_url');
38+
$transport = $mailer->getSymfonyTransport();
39+
40+
$this->assertInstanceOf(EsmtpTransport::class, $transport);
41+
$this->assertSame('usr', $transport->getUsername());
42+
$this->assertSame('pwd', $transport->getPassword());
43+
$this->assertSame('127.0.0.2', $transport->getStream()->getHost());
44+
$this->assertSame(5876, $transport->getStream()->getPort());
45+
}
46+
3047
public static function emptyTransportConfigDataProvider()
3148
{
3249
return [

0 commit comments

Comments
 (0)