Amazon SES Emails in Bulk
I am trying to setup an email queue via Amazon SES to make sure I can send multiple emails at the sametime (limited to 14 emails per second).
I am constantly getting a sign in error
The email was not sent. Error message: Error executing "SendEmail" 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: Sender 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:4d2929e4b7ca73cfe9370d1b848d398d aws-sdk-retry:0/0 host:email.us-west-2.amazonaws.com x-amz-date:20170311T031541Z aws-sdk-invocation-id;aws-sdk-retry;host;x-amz-date 486b4c1288d7c5717c3a0bccdaf10f67eb02ca5da8fbfed75298e98e8f785048' The String-to-Sign should have been 'AWS4-HMAC-SHA256 20170311T031541Z 20170311/us-west-2/email/aws4_request ce02f756d98ab45ab63754fd6ec64a6621c36ed802316ff22c2c877535925735' - Sender SignatureDoesNotMatch 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:4d2929e4b7ca73cfe9370d1b848d398d aws-sdk-retry:0/0 host:email.us-west-2.amazonaws.com x-amz-date:20170311T031541Z aws-sdk-invocation-id;aws-sdk-retry;host;x-amz-date 486b4c1288d7c5717c3a0bccdaf10f67eb02ca5da8fbfed75298e98e8f785048' The String-to-Sign should have been 'AWS4-HMAC-SHA256 20170311T031541Z 20170311/us-west-2/email/aws4_request ce02f756d98ab45ab63754fd6ec64a6621c36ed802316ff22c2c877535925735' 028b5fb9-0609-11e7-9549-6d5ec2e3cc18
and I tried other solutions on stackoverflow without success.
PHP code:
ini_set('display_errors', 'On');
error_reporting(E_ALL);
// aws.amazon.com/code/
// docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-sdk-php.html
// Replace path_to_sdk_inclusion with the path to the SDK as described in
// docs.aws.amazon.com/aws-sdk-php/v3/guide/getting-started/basic-usage.html
define('REQUIRED_FILE','aws/aws-autoloader.php');
// Replace sender@example.com with your "From" address.
// This address must be verified with Amazon SES.
define('SENDER', 'no-reply@mydomain.com');
// Replace recipient@example.com with a "To" address. If your account
// is still in the sandbox, this address must be verified.
define('RECIPIENT', 'admin@mydomain.com');
// Replace us-west-2 with the AWS region you're using for Amazon SES.
define('REGION','us-west-2');
define('SUBJECT','Amazon SES test (AWS SDK for PHP)');
define('BODY','This email was sent with Amazon SES using the AWS SDK for PHP.');
require REQUIRED_FILE;
use AwsSesSesClient;
$client = SesClient::factory(array(
'version'=> 'latest',
'region' => REGION,
'credentials' => array(
'key' => 'xxxx',
'secret' => 'xxxx',
)
));
$request = array();
$request['Source'] = SENDER;
$request['Destination']['ToAddresses'] = array(RECIPIENT);
$request['Message']['Subject']['Data'] = SUBJECT;
$request['Message']['Body']['Text']['Data'] = BODY;
try {
$result = $client->sendEmail($request);
$messageId = $result->get('MessageId');
echo("Email sent! Message ID: $messageId"."n");
} catch (Exception $e) {
echo("The email was not sent. Error message: ");
echo($e->getMessage()."n");
}
You will make my day if you can help.
AWS SES BULK sending library
AWS SDK V3 Documentation
Installation
Step 1. Create Composer.json
{ "require": { "aws/aws-sdk-php": "3.*" } }
Step 2. composer install
AWS SDK V2 Documentation
Installation
This code will work for one-to-one sending using SES AWS SDK version 3. Hope this will work. For sending multiple emails via AWS SES
Use this library AWS SES BULK EMAIL SENDING
<?php
$sesClient = AwsSesSesClient::factory(array(
'credentials' => array(
'key' => $accessKey,
'secret' => $secretKey,
),
"region" => "us-east-1",
"version" => "2010-12-01"
));
$mail = new PHPMailer_PHPMailer();
$mail->CharSet = "UTF-8";
$mail->AddAddress($receiverEmail);
$mail->setFrom($senderEmail, $senderName);
$mail->Subject = $subject;
$mail->preSend();
$mime = $mail->getSentMIMEMessage();
try
{
$response = $sesClient->sendRawEmail(array("RawMessage" => array("Data" => $mime)));
$MessageId = $response->get("MessageId");
$metaData = $response->get("@metadata");
if (!empty($MessageId))
{
$sent[]=$MessageId;
$sent[]=$metaData["headers"]['x-amzn-requestid'];
}
} catch (Exception $ex)
{
echo $response = $ex->getMessage();
$xmlResponse = explode('<Code>', $response);
$parsedResponse = explode('</Code>', $xmlResponse[2]);
$failed[]=$parsedResponse[0];
}
链接地址: http://www.djcxy.com/p/39002.html
上一篇: 亚马逊MWS订单签名不匹配
下一篇: 亚马逊SES邮件散装