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

[8.x] Add Failover Swift Transport driver #38344

Merged
merged 3 commits into from
Aug 12, 2021

Conversation

nerg4l
Copy link
Contributor

@nerg4l nerg4l commented Aug 11, 2021

Sometimes mailgun is not available in our area. The most recent one in the EU was on Aug 2 for ~2 hours and the one before that was on May 29 for ~5 hours (https://status.mailgun.com/). In each cases our clients might lost users by not getting immediate emails. With a "failover" mail transport we could fallback to a different transport driver in the future and help our clients not to lose users.

Swift_FailoverTransport is already battle tested and I was able to provide backward compatibility for "Laravel <= 6.x style mail configuration files".

This feature was requested in 2014 but it was rejected with a comment "No plans to implement this currently.". #3374

My original plan was to develop a provider (https://github.com/coding-socks/laravel-mail-failover) but the whole logic is so simple that in my opinion this could be added to the core library. If you disagree I can still release my lib on packagist.

@taylorotwell
Copy link
Member

Can you explain what it does and how it works?

@nerg4l
Copy link
Contributor Author

nerg4l commented Aug 11, 2021

Of course.

Swift_FailoverTransport accepts a list of transports. It always starts using the first transport and if it fails, it will retry the delivery with the next transports until one of them succeeds or all of them fail.

With this feature one can define in their config/mail.php a failover mailer the following way:

    'mailers' => [
        'failover' => [
            'transport' => 'failover',
            'mailers' => [
                'mailgun',
                'postmark',
                'sendmail',
            ],
        ],

        'mailgun' => [
            'transport' => 'mailgun',
        ],

        'postmark' => [
            'transport' => 'postmark',
        ],

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

With the above configuration when failover is used Swift_FailoverTransport will attempt to send an email with mailgun mailer. If that fails it will attempt to send an email with postmark mailer. If that fails it will attempt to send an email with sendmail mailer. If that fails it will raise an exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants