When trying to send an email using Amazon SES (Simple Email Service) using Laravel's Mail
class.
\Mail::send('email', [], function ($message) {
$message
->from('from@gmail.com', 'John Appleseed')
->to('to@gmail.com', 'Nono Martínez Alonso')
->subject('A sample email')
->html('<p>Hello, this is a test email.</p>');
});
I got the following error.
Expected response code "250" but got code "530",
with message "530 5.7.1 Authentication required".
You need to configure the following environment variables in .env
.
AWS_ACCESS_KEY_ID=XXXXXXXXXXXXXX
AWS_SECRET_ACCESS_KEY=XXXXXXXXXX
AWS_DEFAULT_REGION=us-east-1
And then in config/services.php
.
<?php
return [
// ...
'ses' => [
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
],
];
Lastly, set Amazon SES as Laravel's default mailer in .env
.
MAIL_MAILER=ses
Note that you could also set the default in your config/mail.php
in case there's no MAIL_MAILER
key in your .env
file.
<?php
return [
// ...
'default' => env('MAIL_MAILER', 'ses'),
This is the last error I got before everything worked.
Request to AWS SES API failed.
Email address is not verified.
The following identities failed the check in region US-EAST-1.
I was sending from an unverified email address. Changing it to one of my verified accounts fixed the issue.