我想在Laravel 5.7中发送一个简单的on-demand e-mail notification。
我去了AWS SES,并在电子邮件地址下添加了do-not-reply@foo
作为发件人。然后,我点击do-not-reply@foo
上的验证链接进行确认。
我配置了.env
:
MAIL_FROM_ADDRESS=do-not-reply@foo
MAIL_FROM_NAME="Foo System"
MAIL_DRIVER=smtp
MAIL_HOST=email-smtp.us-west-2.amazonaws.com
MAIL_PORT=587
MAIL_USERNAME=xxx
MAIL_PASSWORD=xxx
MAIL_ENCRYPTION=tls
我从这里获取了用户名和密码:
我做了php artisan config:clear
和php artisan cache:clear
。
现在我的PHP代码如下:
$this->notificationClass = (new ReflectionClass($notificationClass))->getShortName();
$this->notificationData = $notificationData;
$this->notification
->route('slack', config('logging.channels.slack.url')) // slack works great all the time
->route('mail', 'my-inbox-address-123@gmail.com') // this is address where I want notification to be sent
->notify(new $notificationClass(
$this->getNotificationTitle(),
$this->getNotificationContent()
));
$notificationClass
的内容是:
<?php
namespace App\Notifications\Sync;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Messages\SlackMessage;
class SyncSuccessfullyCompletedNotification extends AbstractBaseSyncNotification
{
public function toSlack()
{
return (new SlackMessage)
->success()
->content(sprintf('*Synchronization Successful*```%s```', $this->message));
}
public function toMail()
{
return (new MailMessage)
->from(config('mail.from.address'), config('mail.from.name'))
->subject($this->title)
->view('mail.notifications.sync_successfully_completed_notification', [
'content' => sprintf('<pre>%s</pre>', $this->message),
]);
}
}
所以my-inbox-address-123@gmail.com
只是我的gmail公司收件箱。当我执行负责做某事的artisan命令并发送此通知时,我得到:
Swift_TransportException:预期的响应代码250但得到了代码 “ 554”,并显示消息“ 554消息被拒绝:电子邮件地址不是 已验证。以下身份未能通过签入地区 US-WEST-2:my-inbox-address-123@gmail.com“
在/home/vagrant/Code/iosportal/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:457 453 | $ this-> eventDispatcher-> dispatchEvent($ evt,'responseReceived'); 454 | } 455 | 456 |如果(!$ valid){
457 | $ this-> throwException(new Swift_TransportException('预期的响应代码'.implode('/', 想要)。”但收到代码“'。$ code。'”,并显示消息“'。$ response。'”', $ code)); 458 | } 459 | } 460 | 461 | / **使用其序列号* /
获取完整的多行响应异常跟踪:
1 Swift_Transport_AbstractSmtpTransport :: assertResponseCode(“ 554 邮件被拒绝:电子邮件地址未验证。下列 身份未通过区域US-WEST-2的检查: my-inbox-address-123@gmail.com“) /home/vagrant/Code/iosportal/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:341
2 Swift_Transport_AbstractSmtpTransport :: executeCommand(“。”,[]) /home/vagrant/Code/iosportal/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/EsmtpTransport.php:305
请使用参数-v查看更多详细信息。
为什么?我不明白我的发件人已验证,为什么要验证收件人?
实际上是当我从已验证的帐户向同一已验证的帐户发送此消息时,电子邮件正确到达,但这是胡扯。
答案 0 :(得分:1)
您的帐户必须处于sandbox
模式,这意味着必须验证每个电子邮件地址。
检查您是否处于沙盒模式:
要退出沙盒模式: