Alex
Alex

Reputation: 5668

How to extract delivery failure in SwiftMailer?

Docs for SwiftMailer say:

It’s possible to get a list of addresses that were rejected by the Transport by using a by-reference parameter to send(). As Swift Mailer attempts to send the message to each address given to it, if a recipient is rejected it will be added to the array.

// Pass a variable name to the send() method
if (!$mailer->send($message, $failures))
{
  echo "Failures:";
  print_r($failures);
}

However, I do not see a way to determinate what was the reason for this failure. E.g. send returns 0, $failures is filled with e-mail address, but I would like to know why sending has failed/rejected.

How can I do this? Is it not possible? A quick look inside sources indicate that SwiftMailer catches exceptions to fill $failedRecipients and it seems that exception's message is not saved anywhere. Am I missing something?

Upvotes: 1

Views: 216

Answers (1)

Run_Script
Run_Script

Reputation: 2548

I don't think that it is possible to do this. Unfortunately it is only possible to see the list of email addresses that failed rather than the reasons for these addresses failing.

From the discussion on GitHub (https://github.com/swiftmailer/swiftmailer/issues/891):

Exceptions are swallowed silently in \Swift_Transport_AbstractSmtpTransport::_doMailTransaction()

Upvotes: 1

Related Questions