Laravel 5.7:通过AWS SES进行的按需电子邮件通知将我的收件人电子邮件视为发件人电子邮件,并希望将其作为经过验证的地址

时间:2018-12-24 07:04:02

标签: php laravel amazon-web-services email amazon-ses

我想在Laravel 5.7中发送一个简单的on-demand e-mail notification

我去了AWS SES,并在电子邮件地址下添加了do-not-reply@foo作为发件人。然后,我点击do-not-reply@foo上的验证链接进行确认。

enter image description here

我配置了.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

我从这里获取了用户名和密码:

enter image description here

我做了php artisan config:clearphp 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查看更多详细信息。

为什么?我不明白我的发件人已验证,为什么要验证收件人?

实际上是当我从已验证的帐户向同一已验证的帐户发送此消息时,电子邮件正确到达,但这是胡扯。

1 个答案:

答案 0 :(得分:1)

您的帐户必须处于sandbox模式,这意味着必须验证每个电子邮件地址。

检查您是否处于沙盒模式:

  1. 登录AWS Management Console
  2. 选择您的地区。
  3. 在“电子邮件发送”下,选择“发送统计信息”。
  4. 如果您处于沙盒模式,则会看到一条横幅广告。

要退出沙盒模式:

  1. 登录AWS Management Console
  2. 在支持中心打开一个SES Sending Limit Increase案例。
  3. 填写表格。如果您打算从多个地区发送邮件,请对每个地区重复发送邮件。