Catch failed recipients in Symfony/Mailer 6.x?

1k Views Asked by At

In want replace deprecated SwiftMailer v6.3.0 with new Symfony/Mailer v6.x. In old SwiftMailer I collect failed recipients so that I know who has not received mail.

$successfulRecipients = $mailer->send($message, $failedRecipients);

Symfony/Mailer is not working this way. How do I find failed recipients in Symfony/Mailer? Maybe with try/catch for TransportExceptionInterface but there is no example what exactly is returned.

How do I get the mail addresses which have not received the mail? Because maybe their mailbox was full or the mail was too big?

1

There are 1 best solutions below

0
On

When symfony successfully hands a mail over to the transport server (e.g. SMTP) it is concidered done for symfony.

As you wrote you may can fetch issues with the transport server by using TransportExceptionInterface. This is done by simple try/catch

    use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
    
    $email = new Email();
    try {
        $mailer->send($email);
    } catch (TransportExceptionInterface $e) {
        echo $e->getDebug();
        // error message or try to resend the message

    }