简体   繁体   English

Amazon SES 403 Forbidden SignatureDoesNotMatch 使用 Laravel 5.3

[英]Amazon SES 403 Forbidden SignatureDoesNotMatch using Laravel 5.3

I am using Laravel 5.3, EC2 and SES to send emails.我使用 Laravel 5.3、EC2 和 SES 发送电子邮件。

config/mail.php配置/mail.php

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

.env has .env 有

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作曲家.json

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

EC2 is hosted in Mumbai and SES in us-west. EC2 托管在孟买,SES 托管在美国西部。 I have tried the following :我尝试了以下方法:
1) Creating new IAM user and using the new key/secret. 1) 创建新的 IAM 用户并使用新的密钥/秘密。
2) Creating root user key/secret. 2) 创建 root 用户密钥/秘密。
3) Running NTPDATE command. 3)运行NTPDATE命令。
4) php artisan cache:clear , config:clear, view:clear, dump-autoload 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. 5) 我还在 .env 中使用了 sparkpost,这也给出了错误 403:forbidden。

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完整错误: https : //pastebin.com/KSJinB1E

I was using the 'ses' MAIL_DRIVER in laravel too and had the exact same problem as the OP.我也在MAIL_DRIVER中使用了“ses” MAIL_DRIVER ,并且遇到了与 OP 完全相同的问题。 The issue for me was the IAM user I was using - I used the one that the SES wizard created for me which worked for a while, but then stopped.我的问题是我使用的 IAM 用户 - 我使用了 SES 向导为我创建的用户,该用户工作了一段时间,但后来停止了。 All I had to do to fix it, was create a new 'Programmatic access' IAM user with the "ses:SendRawEmail" permission and emails started flowing.我所要做的就是修复它,就是创建一个具有"ses:SendRawEmail"权限的新“程序访问” IAM 用户,然后电子邮件开始流动。

I am not familiar with Laravel to begin with.一开始我对 Laravel 并不熟悉。 However, if you are using SMTP, you need to specify MAIL_USERNAME and MAIL_PASSWORD .但是,如果您使用 SMTP,则需要指定MAIL_USERNAMEMAIL_PASSWORD Also the driver should be SMTP and not SES since you are using SMTP host of SES.此外,驱动程序应该是SMTP而不是SES因为您使用的是 SES 的 SMTP 主机。

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.文档链接 - http://docs.aws.amazon.com/ses/latest/DeveloperGuide/smtp-credentials.html应该为您提供生成 SMTP 凭证的方法,这些凭证不同于您的 AWS IAM 凭证。

In short, you are not using SES SDK but SMTP to send emails.简而言之,您使用的不是SES SDK,而是SMTP来发送电子邮件。 So SES_KEY and SES_SECRET won't do.所以 SES_KEY 和 SES_SECRET 不行。

1) check your server or local machine's "Date & time" up to date or not. 1)检查您的服务器或本地机器的“日期和时间”是否是最新的。

2) check config/mail.php with below 2) 检查 config/mail.php 与下面

'driver'    => env('MAIL_DRIVER', 'ses'),
'host'      => env('MAIL_HOST'),
'port'      => env('MAIL_PORT', 587),
'encryption'=> env('MAIL_ENCRYPTION', 'tls'),
'username'  => env('MAIL_USERNAME'),
'password'  => env('MAIL_PASSWORD'),
'sendmail'  => '/usr/sbin/sendmail -bs',

3) check your .env file with below 3)用下面的检查你的 .env 文件

MAIL_DRIVER=ses
MAIL_HOST=email-smtp.us-east-1.amazonaws.com
MAIL_PORT=587
MAIL_USERNAME=[your AMI KEY]
MAIL_PASSWORD=[your AMI SECRET]
MAIL_ENCRYPTION=tls

4) check your Config/Services.php file with below 4) 检查您的 Config/Services.php 文件,如下所示

'ses' => [
    'key' => env('MAIL_USERNAME'),
    'secret' => env('MAIL_PASSWORD'),
    'region' => 'us-east-1',// change to your AWS region
],

Don't use amazon ses smtp credentials as MAIL_USERNAME & MAIL_PASSWORD不要使用 amazon ses smtp 凭据作为 MAIL_USERNAME 和 MAIL_PASSWORD

You don't need SMTP username/password, just using IAM key and secret should get u login SES in Laravel...您不需要 SMTP 用户名/密码,只需使用 IAM 密钥和秘密即可让您在 Laravel 中登录 SES...

You seems put necessary quotation marks in key and region, they should be:您似乎在键和区域中放置了必要的引号,它们应该是:

SES_KEY=AKIA------DZQ5TYQ
SES_SECRET=AhN8d----------------ZbBq7TNBmhNnosfYbasg6Q
SES_REGION=us-west-2

If that's not the case, make sure your IAM user has SES write permission:如果不是这种情况,请确保您的 IAM 用户具有SES 写入权限: SES 的 AWS IAM 用户

对我来说,我必须在 .env 文件中指定与 Amazon SES 中验证的相同的电子邮件地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM