【问题标题】:Catch failed recipients in Symfony/Mailer 6.x?在 Symfony/Mailer 6.x 中捕获失败的收件人?
【发布时间】:2022-08-09 03:38:04
【问题描述】:

想要用新的Symfony/Mailer v6.x 替换已弃用的 SwiftMailer v6.3.0。在旧的 SwiftMailer 中,我收集 failed recipients 以便我知道谁没有收到邮件。

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

Symfony/Mailer 不是这样工作的。如何在 Symfony/Mailer 中找到失败的收件人?可能使用 TransportExceptionInterface 的 try/catch,但没有具体返回的示例。

如何获取未收到邮件的邮件地址?因为也许他们的邮箱已满或邮件太大?

    标签: symfony-mailer


    【解决方案1】:

    当 symfony 成功地将邮件交给传输服务器(例如 SMTP)时,它被认为是为 symfony 完成的。

    正如您所写,您可以使用TransportExceptionInterface 获取传输服务器的问题。这是通过简单的 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
    
        } 
    

    【讨论】:

      猜你喜欢
      • 2022-01-08
      • 1970-01-01
      • 1970-01-01
      • 2013-03-03
      • 1970-01-01
      • 2014-09-05
      • 2012-05-14
      • 2019-01-03
      • 1970-01-01
      相关资源
      最近更新 更多