Search code examples
amazon-web-serviceslaravel-5amazon-ec2aws-sdkamazon-ses

Amazon SES 403 Forbidden SignatureDoesNotMatch using Laravel 5.3


I am using Laravel 5.3, EC2 and SES to send emails.

config/mail.php

'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),

.env has

MAIL_DRIVER=ses
MAIL_HOST=email-smtp.us-west-2.amazonaws.com
MAIL_PORT=25
MAIL_ENCRYPTION=TLS
SES_KEY='AKIA------DZQ5TYQ'
SES_SECRET=AhN8d----------------ZbBq7TNBmhNnosfYbasg6Q
SES_REGION='us-west-2'

composer.json

"require": {
    "aws/aws-sdk-php": "~3.0", 
}

EC2 is hosted in Mumbai and SES in us-west. I have tried the following :
1) Creating new IAM user and using the new key/secret.
2) Creating root user key/secret.
3) Running NTPDATE command.
4) php artisan cache:clear , config:clear, view:clear, dump-autoload
5) I also used sparkpost in .env and that gives error 403:forbidden too.

I am still seeing the following error :

[2017-05-26 06:02:00] local.ERROR: exception 'Aws\Ses\Exception\SesException' with message 'Error executing "SendRawEmail" on "https://email.us-west-2.amazonaws.com"; AWS HTTP error: Client error: `POST https://email.us-west-2.amazonaws.com` resulted in a `403 Forbidden` response:
<ErrorResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
  <Error>
    <Type>Sender</Type>
    <Code>SignatureDo (truncated...)
 SignatureDoesNotMatch (client): 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.

Full error here : https://pastebin.com/KSJinB1E


Solution

  • I am not familiar with Laravel to begin with. However, if you are using SMTP, you need to specify MAIL_USERNAME and MAIL_PASSWORD. Also the driver should be SMTP and not SES since you are using SMTP host of SES.

    The documentation link - http://docs.aws.amazon.com/ses/latest/DeveloperGuide/smtp-credentials.html should provide you with ways to generate SMTP credentials which are different from your AWS IAM credentials.

    In short, you are not using SES SDK but SMTP to send emails. So SES_KEY and SES_SECRET won't do.