1
votes

I am setting up Amazon SES for the first time. Following the documentation on Laravel website I have installed a package and started to set up mail.

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

Mail/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>

Controller:

public function map(Request $request)
{
    Mail::to($request->user())->send(new WelcomeEmail());
    return view('profile.map');
}

And error:

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>

However, I am sure that SES_key and secret is correct, domain is verified, and email also, what am I missing?

2
Is the date/time on your server accurate to within about a minute of the actual time?ceejayoz
Yes, it not says that the email I am sending to is not verified? FROM email is verified but TO isn't, I mean that doesn't exactly make any sense because I want to be able to send emails to anyonePrzemek Wojtas
SES_SECRET can't find these anywhere. I have the smtp creds, but where do we find the SES_SECRET & SES_KEY? They don't seem to exist.Jordan

2 Answers

1
votes

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

This means you're in the SES "sandbox".

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

During development:

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

Moving from sandbox to production (where you can send email to anyone) is easy enough - just fill out the form at https://aws.amazon.com/ses/extendedaccessrequest/.

0
votes

it's means your in sandbox mode and in sandbox mode only verified email get maild so either move from sandbox to production or verify your mail for testing mail but at last you have to move in production