【问题标题】:Laravel: Send emails only if the email is not on bounce listLaravel:仅当电子邮件不在退回列表中时才发送电子邮件
【发布时间】:2016-12-30 15:36:28
【问题描述】:
我正在使用 Laravel 5.3 和 SES 驱动程序来发送我的电子邮件。
我已经设置了我的数据库和路由,这样每当我发送一封退回的电子邮件时,我都会收到通知并将这封电子邮件添加到“无效电子邮件”表中。
现在我需要设置我的应用程序,以便它仅在电子邮件不在此退回表中时发送电子邮件。对此应用程序发送的每封电子邮件都会进行检查,无一例外。
是否有一种简单的方法可以在电子邮件驱动程序上进行此检查,或者我是否需要更改对 Mail 门面的所有调用并在发送电子邮件之前进行检查?
【问题讨论】:
标签:
php
laravel
email
laravel-5
amazon-ses
【解决方案1】:
我建议创建自己的 Mailable 类,该类继承自 \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;
}
你可以加入(覆盖)这个并添加一些逻辑来只添加不在“阻止”列表中的收件人。