mailersend-laravel-driver icon indicating copy to clipboard operation
mailersend-laravel-driver copied to clipboard

Add support for failover

Open kavanpancholi opened this issue 1 year ago • 1 comments
trafficstars

Laravel provides failover configuration for the mail drivers. That means, in case the mail driver doesn't work, it would retry with the next registered driver to send emails. Doc: https://laravel.com/docs/10.x/mail#failover-configuration

Currently, it doesn't work with mailersend. The reason it doesn't work is because Symfony's Mail Transport catches exceptions through TransportExceptionInterface. However, when something goes wrong, MailerSend throws MailerSendException. Ref: https://github.com/symfony/mailer/blob/7.0/Transport/RoundRobinTransport.php#L56-L60

And because of that, it doesn't find the exception and can not retry with another fallback driver.

Now to make this work, we need to throw TransportException instead of MailerSendException.

kavanpancholi avatar Mar 01 '24 11:03 kavanpancholi

We should catch MailerSendHttpException and "convert" it to TransportException. In other cases, return MailerSendException as intended.

fosron avatar Mar 01 '24 14:03 fosron

@kavanpancholi I think we can close this one right?

PeterOcansey avatar Nov 18 '24 09:11 PeterOcansey

Yes for sure. Closing now.

kavanpancholi avatar Nov 18 '24 09:11 kavanpancholi