2017-07-26 179 views
0

我正在首次設置亞馬遜SES。在Laravel網站上的文檔之後,我安裝了一個軟件包並開始設置郵件。Laravel和Amazon SES

mail.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', '[email protected]'), 
     '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'), 
     ], 
    ], 

]; 

services.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 

郵件/ WelcomeEmail.php

<?php 

namespace App\Mail; 

use Illuminate\Bus\Queueable; 
use Illuminate\Mail\Mailable; 
use Illuminate\Queue\SerializesModels; 
use Illuminate\Contracts\Queue\ShouldQueue; 

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('[email protected]') 
        ->view('emails.welcomeEmail'); 
    } 
} 

welcomeEmail.blade.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和祕密是正確的,域名被驗證,電子郵件也是,我錯過了什麼?

+0

移動是日期/時間在您的服務器上精確到實際時間的大約一分鐘內? – ceejayoz

+0

是的,它不是說我發送的郵件沒有被驗證? FROM電子郵件已通過驗證,但TO不是,我的意思是,這並沒有任何意義,因爲我希望能夠將電子郵件發送給任何人 –

回答

0

Yes, it not says that the email I am sending to is not verified?

這意味着你在SES「沙盒」中。

http://docs.aws.amazon.com/ses/latest/DeveloperGuide/request-production-access.html

在開發過程中:

  • You can only send mail to the Amazon SES mailbox simulator and to verified email addresses and domains.
  • You can only send mail from verified email addresses and domains.
  • You can send a maximum of 200 messages per 24-hour period.
  • Amazon SES can accept a maximum of one message from your account per second.

從沙箱移動到生產(在這裏您可以發送電子郵件給任何人)是很容易 - 只需填寫表格的https://aws.amazon.com/ses/extendedaccessrequest/

0

這意味着你在沙盒模式和沙盒模式下,只驗證電子郵件獲取maild所以從沙盤上移,以生產或驗證您的郵件測試郵件,但最後你必須在生產