skip to Main Content

I am trying to send email in my Laravel project using AWS SES.
The error messages are not being very helpful.

In AWS SES, I verified the identity of both my domain and the email address I’m using as sender in my test.
In AWS IAM Manager, I generated a Key-pair.
I’m confident that this part is working fine because I used it to send mail in a previous PHP application with PHPMailer in the same EC2 server.
On the server side, an EC2 instance running Ubuntu, I installed the package according to Laravel manual:
composer require aws/aws-sdk-php
In config/mail.php:

<?php
return [
'default' => env('MAIL_MAILER', 'smtp'),
'mailers' => [
'ses' => [
            'transport' => ‘ses',
            'host' => env('MAIL_HOST'),
            'key' => env('SES_ACCESS_KEY_ID'),
            'secret' => env('SES_SECRET_ACCESS_KEY'),
            'region' => env('SES_DEFAULT_REGION', 'us-east-1'),
            'encryption' => 'tls',
            'port' => 587,
        ],
], 
'from' => [
        'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
        'name' => env('MAIL_FROM_NAME', 'Example'),
    ],
];

In config/services.php:

<?php
return [
    'ses' => [
        'key' => env('SES_ACCESS_KEY_ID'),
        'secret' => env('SES_SECRET_ACCESS_KEY'),
        'region' => env('SES_DEFAULT_REGION', 'us-east-1'),
    ],
];

In .env:

MAIL_MAILER=ses
MAIL_HOST="email-smtp.sa-east-1.amazonaws.com"
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="${APP_NAME}"
MAIL_EHLO_DOMAIN="my-verified-domain.com"
SES_DEFAULT_REGION=sa-east-1
SES_ACCESS_KEY_ID=”MY-KEY-ID, TRIED QUOTED AND NOT QUOTED”
SES_SECRET_ACCESS_KEY= “MY-SAK, TRIED QUOTED AND NOT QUOTED”

After the setup, I ran:
php artisan config:clear (even though my project is not caching the configuration)
php artisan tinker
In Tinker:
Mail::raw("TEST BODY", function($msg){ $msg->to("[email protected]")->subject("TEST SUBJECT"); });
The command is throwing this Exception:

Exception Request to AWS SES API failed. Reason: The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details..

For debugging purpose, I ran:
dd(config('mail'));
Everything seems OK:

array:4 [ // vendor/psy/psysh/src/ExecutionLoopClosure.php(53) : eval()'d code:1
  "default" => "ses"
  "mailers" => array:1 [
    "ses" => array:7 [
      "transport" => "ses"
      "host" => "email-smtp.sa-east-1.amazonaws.com"
      "key" => " MY-KEY-ID"
      "secret" => "MY-SECRET"
      "region" => "sa-east-1"
      "encryption" => "tls"
      "port" => 587
    ]
  ]
  "from" => array:2 [
    "address" => "[email protected]"
    "name" => " LARAVEL_APP "
  ]
  "contact" => array:1 [
    "address" => "LARAVEL_APP"
  ]
]

I don’t know if it is of any help, but I’ll add some additional testing I already tried:
If I change the Transport to ‘smtp’, the error is:

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

As I said before, the SES credentials are working fine in another application (not a Laravel one) in the same EC2 server. Even so, I tried creating new ones also, facing the same error.
Finally, I tried different combinations of the mailer array, removing the keys: ‘host’, ‘region’, ‘encryption’ and ‘port’.
What I am doing wrong here?!

2

Answers


  1. Possible Reasons

    1. Cross Check that Sender Email address is Verified on AWS SES or Not
    2. Cross Check the Authtype [PLAIN, LOGIN, CRAM-MD5]- Try All
    3. Cross test on all STARTTLS/TLS/SSL- Try All
    4. try to telnet the port, and try to send email from console and check the return status
    5. Test on Debug level 4 and share the output
    Login or Signup to reply.
  2. Confirm that the region you’re using matches the region of your SES setup in AWS.

    In your .env file, you’ve set SES_DEFAULT_REGION to sa-east-1, but in your SES configuration, the region is set to us-east-1.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search