Laravel Send email using AWS SES

639 Views Asked by At

I have the following config from aws in my laravel 5.7 app (admin.my-app.com) that i'm maintaining.

my .env

MAIL_MAILER=ses
SES_KEY=aws_key_here
SES_KEY_SECRET=aws_secret_key_here
SES_REGION=us-east-1
[email protected]
MAIL_FROM_NAME="${APP_NAME}"

my config/mail.php

<?php

return [
    'default' => env('MAIL_MAILER', 'smtp'),
//other configs

my config/services.php

<?php

return [
    'ses' => [
        'key' => env('SES_KEY'),
        'secret' => env('SES_KEY_SECRET'),
        'region' => env('SES_REGION', 'us-east-1'),
    ],
    //other configs

Code to trigger email sending

    public function approveKyc(Request $request, $userId)
    {
        $model = User::on('mysql2')->find($userId);

        $this->actionKyc($userId, 'is_verified');


        $model->notify(new KycApproved());

        return response()->json([
            'name' => 'New KYC Docs',
            'status' => 'Approved'
        ]);
    }

I've also checed composer file "aws/aws-sdk-php": "^3.86", is installed.

With the above code i'm getting error message

exception : "Swift_TransportException" file : "/var/www/my-app/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php" line : 460 message : "Expected response code 354 but got code "503", with message "503 RCPT command expected\r\n""

I tested sending email with mailtrap it works fine. Additionally I used smtp settings from cpanel account it was also working (Email sent sucessfully).

Using aws is not sending the email.

I'm also using the above aws config in another laravel 10 app with sub domain (api.myapp.com). It works fine there.

Can anyone help me figure-out what am i missing here ?

1

There are 1 best solutions below

1
On

AWS SES has a "Sandbox" mode that comes with several restrictions. Due to these restrictions, you can only send mail to verified email addresses or domains, or to the Amazon SES mailbox simulator. However, if you're trying to send to an unverified email address while in Sandbox mode, SES will reject the send request. You should get Approvement from AWS team before using it in prod.