我是第一次设置 Amazon SES。按照Laravel网站上的文档,我安装了一个软件包并开始设置邮件。
邮件.php
<?php
return [
'driver' => env('MAIL_DRIVER', 'ses'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
服务.php
'ses' => [
'key' => env('SES_KEY'),
'secret' => env('SES_SECRET'),
'region' => 'eu-west-1',
],
.env
MAIL_DRIVER=ses
SES_KEY=ASKFKGDRJ3
SES_SECRET=kdfsjjdsfjdfsjdfsj
MAIL_HOST=email.eu-west-1.amazonaws.com
MAIL_PORT=587
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
邮件/欢迎电子邮件.php
<?php
namespace AppMail;
use IlluminateBusQueueable;
use IlluminateMailMailable;
use IlluminateQueueSerializesModels;
use IlluminateContractsQueueShouldQueue;
class WelcomeEmail extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->from('test@gmail.com')
->view('emails.welcomeEmail');
}
}
欢迎电子邮件刀片.php
<p>This is a test email from test email address, let me know on slack if you receive it</p>
控制器:
public function map(Request $request)
{
Mail::to($request->user())->send(new WelcomeEmail());
return view('profile.map');
}
和错误:
Error executing "SendRawEmail" on "https://email.eu-west-1.amazonaws.com"; AWS HTTP error: Client error: `POST https://email.eu-west-1.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.
The Canonical String for this request should have been
'POST
/
aws-sdk-invocation-id:7a73507566587348bba7c543661be161
aws-sdk-retry:0/0
host:email.eu-west-1.amazonaws.com
x-amz-date:20170726T195108Z
aws-sdk-invocation-id;aws-sdk-retry;host;x-amz-date
7a1f353a7f93f014d66ee19fb4b9661a79fea8411d1f97af2799c0cc04dc57dc'
The String-to-Sign should have been
'AWS4-HMAC-SHA256
20170726T195108Z
20170726/eu-west-1/ses/aws4_request
c2422180627319d05721ed6a2dc3973f7a508c34e4b2f9699d0a7bbf0c56d6a8'
- <ErrorResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
<Error>
<Type>Sender</Type>
<Code>SignatureDoesNotMatch</Code>
<Message>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.
The Canonical String for this request should have been
'POST
/
aws-sdk-invocation-id:7a73507566587348bba7c543661be161
aws-sdk-retry:0/0
host:email.eu-west-1.amazonaws.com
x-amz-date:20170726T195108Z
aws-sdk-invocation-id;aws-sdk-retry;host;x-amz-date
7a1f353a7f93f014d66ee19fb4b9661a79fea8411d1f97af2799c0cc04dc57dc'
The String-to-Sign should have been
'AWS4-HMAC-SHA256
20170726T195108Z
20170726/eu-west-1/ses/aws4_request
c2422180627319d05721ed6a2dc3973f7a508c34e4b2f9699d0a7bbf0c56d6a8'
</Message>
</Error>
<RequestId>c458f296-723b-11e7-a686-515a08ffcc2f</RequestId>
</ErrorResponse>
但是,我确定SES_key和秘密是正确的,域已验证,电子邮件也已验证,我错过了什么?
是的,它不是说我发送到的电子邮件未经过验证吗?
这意味着您处于SES"沙盒"中。
http://docs.aws.amazon.com/ses/latest/DeveloperGuide/request-production-access.html
在开发过程中:
- 您只能将邮件发送到 Amazon SES 邮箱模拟器以及已验证的电子邮件地址和域。
- 您只能从经过验证的电子邮件地址和网域发送邮件。
- 每 24 小时最多可以发送 200 条消息。
- Amazon SES 每秒最多可以接受来自您账户的一封邮件。
从沙盒迁移到生产环境(您可以在其中向任何人发送电子邮件(非常简单 - 只需在 https://aws.amazon.com/ses/extendedaccessrequest/填写表单即可。
这意味着您在沙盒模式和沙盒模式下只有经过验证的电子邮件才会被邮寄,因此要么从沙盒移动到生产环境,要么验证您的邮件以测试邮件,但最后您必须在生产环境中移动