Skip to content
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
29 changes: 21 additions & 8 deletions src/Illuminate/Mail/MailManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,28 @@ protected function resolve($name)
// Once we have created the mailer instance we will set a container instance
// on the mailer. This allows us to resolve mailer classes via containers
// for maximum testability on said classes instead of passing Closures.
$mailer = $this->build(['name' => $name, ...$config]);

// Next we will set all of the global addresses on this mailer, which allows
// for easy unification of all "from" addresses as well as easy debugging
// of sent messages since these will be sent to a single email address.
foreach (['from', 'reply_to', 'to', 'return_path'] as $type) {
$this->setGlobalAddress($mailer, $config, $type);
}

return $mailer;
}

/**
* Build a new mailer instance.
*
* @param array $config
* @return \Illuminate\Mail\Mailer
*/
public function build($config)
{
$mailer = new Mailer(
$name,
$config['name'] ?? 'ondemand',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use ondemand as the driver name in the FilesystemManager:

return $this->resolve('ondemand', is_array($config) ? $config : [

$this->app['view'],
$this->createSymfonyTransport($config),
$this->app['events']
Expand All @@ -131,13 +151,6 @@ protected function resolve($name)
$mailer->setQueue($this->app['queue']);
}

// Next we will set all of the global addresses on this mailer, which allows
// for easy unification of all "from" addresses as well as easy debugging
// of sent messages since these will be sent to a single email address.
foreach (['from', 'reply_to', 'to', 'return_path'] as $type) {
$this->setGlobalAddress($mailer, $config, $type);
}

return $mailer;
}

Expand Down
1 change: 1 addition & 0 deletions src/Illuminate/Support/Facades/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/**
* @method static \Illuminate\Contracts\Mail\Mailer mailer(string|null $name = null)
* @method static \Illuminate\Mail\Mailer driver(string|null $driver = null)
* @method static \Illuminate\Mail\Mailer build(array $config)
* @method static \Symfony\Component\Mailer\Transport\TransportInterface createSymfonyTransport(array $config)
* @method static string getDefaultDriver()
* @method static void setDefaultDriver(string $name)
Expand Down
22 changes: 22 additions & 0 deletions tests/Mail/MailManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,28 @@ public function testMailUrlConfig()
$this->assertSame(5876, $transport->getStream()->getPort());
}

public function testBuild()
{
$config = [
'transport' => 'smtp',
'host' => '127.0.0.2',
'port' => 5876,
'encryption' => 'tls',
'username' => 'usr',
'password' => 'pwd',
'timeout' => 5,
];

$mailer = $this->app['mail.manager']->build($config);
$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(5876, $transport->getStream()->getPort());
}

public static function emptyTransportConfigDataProvider()
{
return [
Expand Down