I want to send a simple on-demand e-mail notification in Laravel 5.7.
I went to AWS SES and under Email Addresses I added do-not-reply@foo
as a sender. Then I click on the verification link on do-not-reply@foo
to confirm it.
I configured my .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
I took username and password from here:
I did php artisan config:clear
and php artisan cache:clear
.
Now in terms of my PHP code I have:
$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()
));
And the content of $notificationClass
is:
<?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),
]);
}
}
So my-inbox-address-123@gmail.com
is just my gmail company inbox. When I execute the artisan command responsible for doing something and sending this notification I get:
Swift_TransportException : Expected response code 250 but got code "554", with message "554 Message rejected: Email address is not verified. The following identities failed the check in region US-WEST-2: my-inbox-address-123@gmail.com "
at /home/vagrant/Code/iosportal/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:457 453| $this->eventDispatcher->dispatchEvent($evt, 'responseReceived'); 454| } 455| 456| if (!$valid) {
457| $this->throwException(new Swift_TransportException('Expected response code '.implode('/', $wanted).' but got code "'.$code.'", with message "'.$response.'"', $code)); 458| } 459| } 460| 461| /** Get an entire multi-line response using its sequence number */
Exception trace:
1 Swift_Transport_AbstractSmtpTransport::assertResponseCode("554 Message rejected: Email address is not verified. The following identities failed the check in region 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
Please use the argument -v to see more details.
Why? I don't get this. My sender is verified, why it wants to verify a recipient?
Indeed when I send this message from verified account to the same verified account the email arrives correctly, but this is nonsense.
Your account must be in sandbox
mode, which means every email address has to be verified.
Check if you are in sandbox mode:
To get out of sandbox mode: