Laravel:从 Mailable 获取 bad_domains

Laravel: Get bad_domains from Mailable

我用 Laravel 发送邮件是这样的:

foreach ($users as $user) {
   \Mail::to($user())->send(new Newsletter($user));
}

我想要一个包含有 bad_domain 响应的所有用户的数组。我在 docs that Laravel uses Swiftmailer which has a way to find bad_domain respones:

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

/*
Failures:
Array (
  0 => receiver@bad-domain.org,
  1 => other-receiver@bad-domain.org
)
*/

不过,我想使用 Mailable class。我不确定如何使用 Swiftmailer 执行此操作(我可以通过 \Mail::getSwiftMailer() 访问)。

在使用来自 Laravel 的 Mailable 时,有什么简单的方法可以获取 bad_domain 吗?

You may only access bad_domains, but not bounces with Swiftmailer (Swiftmailer 4 does not retrieve bounces as $failedRecipients).

可以得到bad_domains
\Mail::to($user)->send(new \App\Mail\Hi());

dd(\Mail::failures());

Illuminate\Mail\Mailer.php

  /**
     * Send a Swift Message instance.
     *
     * @param  \Swift_Message  $message
     * @return void
     */
    protected function sendSwiftMessage($message)
    {
        try {
            return $this->swift->send($message, $this->failedRecipients);
        } finally {
            $this->forceReconnection();
        }
    }