Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[12.x] Allow configuration of retry period for RoundRobin and Failover mail transports #55222

Merged
Merged
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
2 changes: 2 additions & 0 deletions config/mail.php
Original file line number Diff line number Diff line change
@@ -85,6 +85,7 @@
'smtp',
'log',
],
'retry_after' => 60,
],

'roundrobin' => [
@@ -93,6 +94,7 @@
'ses',
'postmark',
],
'retry_after' => 60,
],

],
35 changes: 16 additions & 19 deletions src/Illuminate/Mail/MailManager.php
Original file line number Diff line number Diff line change
@@ -385,24 +385,7 @@ protected function createPostmarkTransport(array $config)
*/
protected function createFailoverTransport(array $config)
{
$transports = [];

foreach ($config['mailers'] as $name) {
$config = $this->getConfig($name);

if (is_null($config)) {
throw new InvalidArgumentException("Mailer [{$name}] is not defined.");
}

// Now, we will check if the "driver" key exists and if it does we will set
// the transport configuration parameter in order to offer compatibility
// with any Laravel <= 6.x application style mail configuration files.
$transports[] = $this->app['config']['mail.driver']
? $this->createSymfonyTransport(array_merge($config, ['transport' => $name]))
: $this->createSymfonyTransport($config);
}

return new FailoverTransport($transports);
return $this->createRoundrobinTransportOfClass($config, FailoverTransport::class);
}

/**
@@ -412,6 +395,20 @@ protected function createFailoverTransport(array $config)
* @return \Symfony\Component\Mailer\Transport\RoundRobinTransport
*/
protected function createRoundrobinTransport(array $config)
{
return $this->createRoundrobinTransportOfClass($config, RoundRobinTransport::class);
}

/**
* Create an instance of supplied class extending the Symfony Roundrobin Transport driver.
*
* @template TClass of \Symfony\Component\Mailer\Transport\RoundRobinTransport
*
* @param array $config
* @param class-string<TClass> $class
* @return TClass
*/
protected function createRoundrobinTransportOfClass(array $config, string $class)
{
$transports = [];

@@ -430,7 +427,7 @@ protected function createRoundrobinTransport(array $config)
: $this->createSymfonyTransport($config);
}

return new RoundRobinTransport($transports);
return new $class($transports, $config['retry_after'] ?? 60);
}

/**
27 changes: 0 additions & 27 deletions tests/Integration/Mail/MailRoundRobinTransportTest.php

This file was deleted.

51 changes: 51 additions & 0 deletions tests/Mail/MailRoundRobinTransportTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace Illuminate\Tests\Mail;

use Orchestra\Testbench\TestCase;
use Symfony\Component\Mailer\Transport\RoundRobinTransport;

class MailRoundRobinTransportTest extends TestCase
{
public function testGetRoundRobinTransportWithConfiguredTransports()
{
$this->app['config']->set('mail.default', 'roundrobin');

$this->app['config']->set('mail.mailers', [
'roundrobin' => [
'transport' => 'roundrobin',
'mailers' => [
'sendmail',
'array',
],
],

'sendmail' => [
'transport' => 'sendmail',
'path' => '/usr/sbin/sendmail -bs',
],

'array' => [
'transport' => 'array',
],
]);

$transport = app('mailer')->getSymfonyTransport();
$this->assertInstanceOf(RoundRobinTransport::class, $transport);
}

public function testGetRoundRobinTransportWithLaravel6StyleMailConfiguration()
{
$this->app['config']->set('mail.driver', 'roundrobin');

$this->app['config']->set('mail.mailers', [
'sendmail',
'array',
]);

$this->app['config']->set('mail.sendmail', '/usr/sbin/sendmail -bs');

$transport = app('mailer')->getSymfonyTransport();
$this->assertInstanceOf(RoundRobinTransport::class, $transport);
}
}