Laravel:仅当电子邮件不在退回列表中时才发送电子邮件

Laravel: Send emails only if the email is not on bounce list

我正在使用 Laravel 5.3 和 SES 驱动程序来发送我的电子邮件。 我已经设置了我的数据库和路由,这样,每当我发送一封 returns 退回的电子邮件时,我都会收到通知并将这封电子邮件添加到 "invalid emails" 的 table。

现在我需要设置我的应用程序,以便它仅在电子邮件不在此退回中时才发送电子邮件 table。此应用程序发送的每一封电子邮件都会进行检查,无一例外。

是否有一种简单的方法可以在电子邮件驱动程序上进行此检查,或者我是否需要更改对 Mail facade 的所有调用并在发送电子邮件之前进行检查?

我建议创建您自己的 Mailable class,它继承自 \Illuminate\Mail\Mailable

那里有一个名为 buildRecipients() 的方法,它看起来像这样:

/**
 * Add all of the recipients to the message.
 *
 * @param  \Illuminate\Mail\Message  $message
 * @return $this
 */
protected function buildRecipients($message)
{
    foreach (['to', 'cc', 'bcc', 'replyTo'] as $type) {
        foreach ($this->{$type} as $recipient) {
            $message->{$type}($recipient['address'], $recipient['name']);
        }
    }

    return $this;
}

您可以挂钩(覆盖)它并添加一些逻辑以仅添加收件人,如果他不在 "blocked" 列表中。