批量发送 Amazon SES 电子邮件
Amazon SES Emails in Bulk
我正在尝试通过 Amazon SES 设置电子邮件队列以确保我可以同时发送多封电子邮件(限制为每秒 14 封电子邮件)。
我经常遇到登录错误
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
我在 Whosebug 上尝试了其他解决方案但没有成功。
PHP代码:
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 Aws\Ses\SesClient;
$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");
}
如果你能帮上忙,我会很高兴的。
安装
步骤 1.
Create Composer.json
{
"require": {
"aws/aws-sdk-php": "3.*"
}
}
步骤 2.
composer install
此代码适用于使用 SES AWS SDK 版本 3 的一对一发送。希望这会奏效。用于发送 multiple emails via AWS SES
使用此库 AWS SES BULK EMAIL SENDING
<?php
$sesClient = Aws\Ses\SesClient::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];
}
我正在尝试通过 Amazon SES 设置电子邮件队列以确保我可以同时发送多封电子邮件(限制为每秒 14 封电子邮件)。
我经常遇到登录错误
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 a403 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
我在 Whosebug 上尝试了其他解决方案但没有成功。
PHP代码:
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 Aws\Ses\SesClient;
$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");
}
如果你能帮上忙,我会很高兴的。
安装
步骤 1.
Create Composer.json
{
"require": {
"aws/aws-sdk-php": "3.*"
}
}
步骤 2.
composer install
此代码适用于使用 SES AWS SDK 版本 3 的一对一发送。希望这会奏效。用于发送 multiple emails via AWS SES
使用此库 AWS SES BULK EMAIL SENDING
<?php
$sesClient = Aws\Ses\SesClient::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];
}