Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel won't send through AWS SES SMTP

I'm running Laravel 5.4.24 and I can't get it to send through Amazon SES SMTP.

However when I download SwiftMailer and run it standalone I can.

Working..

require("vendor/autoload.php");

// Create the Transport
$transport = new Swift_SmtpTransport('email-smtp.us-west-2.amazonaws.com', 587, 'tls');
$transport->setUsername('A**************A');
$transport->setPassword('A****************************m');

// Create the Mailer using your created Transport
$mailer = new Swift_Mailer($transport);

// Create a message
$message = new Swift_Message('Wonderful Subject');

$message->setFrom(['noreply@su*****th.com' => 'John Doe']);

$message->setTo(['j*******@gmail.com' => 'Jamie']);

$message->setBody('Here is the message itself');

// Send the message
$result = $mailer->send($message);

Laravel setup thats not working

MAIL_DRIVER=smtp
MAIL_HOST=email-smtp.us-west-2.amazonaws.com
MAIL_PORT=587
MAIL_USERNAME=A****************A
MAIL_PASSWORD=A************************m
MAIL_ENCRYPTION=tls

Even though the credentials are identical I get

Expected response code 250 but got code "530", with message "530 Authentication required

I've tried

php artisan queue:restart
php artisan config:cache

This is how I'm using Mail in code

Mail::send('emails.verify', $data, function($message) use ($data)
{
    $message->from('noreply@su*****h.com', "Jamie - ****");
    $message->subject("Please verify your email address");
    $message->to($data['email']);
});

But with no luck.

Any ideas?

like image 692
Mr J Avatar asked Dec 08 '25 08:12

Mr J


1 Answers

The SES keys and Region are configured in the config/services.php file.

So for me the issue was that even though I already had my default region set to us-west-2 in my other AWS configs SES uses its own config in the Services file which was set directly to 'us-east-1' and not using the existing AWS keys in my .env file.

like image 161
Richard Avatar answered Dec 09 '25 21:12

Richard