Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Catching failed email recipients in Laravel 9 (Symfony Mailer)

I have recently upgraded my Laravel application from 5.8 to 9.x. In the previous version of Laravel, mail transport was done by SwiftMailer. But now in Laravel 9, it uses SymfonyMailer.

To get the failed recipient list, Mail::failures() was used, which returned an array of email addresses. In Laravel 9, this method is not available.

Is there any way to get the array of failed recipients?

like image 868
Naowas Morshed Eimon Avatar asked Sep 17 '25 08:09

Naowas Morshed Eimon


1 Answers

Does this helps, https://symfony.com/doc/current/mailer.html#handling-sending-failures

Symfony Mailer considers that sending was successful when your transport (SMTP server or third-party provider) accepts the mail for further delivery. The message can later be lost or not delivered because of some problem in your provider, but that's out of reach for your Symfony application.

If there's an error when handing over the email to your transport, Symfony throws a TransportExceptionInterface. Catch that exception to recover from the error or to display some message:

use Symfony\Component\Mailer\Exception\TransportExceptionInterface;

$email = new Email();
// ...
try {
    $mailer->send($email);
} catch (TransportExceptionInterface $e) {
    // some error prevented the email sending; display an
    // error message or try to resend the message
}
like image 84
Vipertecpro Avatar answered Sep 19 '25 23:09

Vipertecpro