当我尝试发送电子邮件时,AWS SES没有回复



我最近的电子邮件有一个问题,一周前我开始在发送电子邮件时出错,问题是有时当我调用此函数sendEmail时,它永远不会返回Aws/Result或任何Exception。所以我的脚本是循环等待它。这个问题是偶发的。我假设我的请求无法添加到AWS队列中,但我至少会得到一个异常。

我试图找到一个可以设置为不永远等待的超时设置,但在文档中找不到。我已经使用这项服务两年了,直到现在我还没有出现错误。

其他人经历过这个问题吗?

在哪里可以设置与SES类相关的调用的超时?

简单代码:

use AwsSesSesClient;
use AwsSesExceptionSesException;
// Replace sender@example.com with your "From" address.
// This address must be verified with Amazon SES.
define('SENDER', 'sender@example');
// Replace recipient@example.com with a "To" address. If your account
// is still in the sandbox, this address must be verified.
define('RECIPIENT', 'recipient@example.com');
define('SUBJECT', 'Amazon SES test (AWS SDK for PHP)');
define('HTMLBODY', '<h1>AWS Amazon Simple Email Service Test Email</h1>' .
'<p>This email was sent with <a href="https://aws.amazon.com/ses/">' .
'Amazon SES</a> using the <a href="https://aws.amazon.com/sdk-for-php/">' .
'AWS SDK for PHP</a>.</p>');
define('TEXTBODY', 'This email was send with Amazon SES using the AWS SDK for PHP.');
define('CHARSET', 'UTF-8');
$_AWSAPICredentials = array(
'key' => 'AWSAPIKEY',
'secret' => 'AWSAPISECRET',
);
$_AWSAPIVersion = 'latest';
$_AWSAPIRegion = 'us-west-2';
$_SES = new SesClient([
'version' => $_AWSAPIVersion,
'region' => $_AWSAPIRegion,
'credentials' => $_AWSAPICredentials,
]);
$params = [
'Destination' => [
'ToAddresses' => [
RECIPIENT,
],
],
'Message' => [
'Body' => [
'Html' => [
'Charset' => CHARSET,
'Data' => HTMLBODY,
],
'Text' => [
'Charset' => CHARSET,
'Data' => TEXTBODY,
],
],
'Subject' => [
'Charset' => CHARSET,
'Data' => SUBJECT,
],
],
'Source' => SENDER
];
try {
$result = $_SES->sendEmail($params);
$sMessageId = $result->get('MessageId');
} catch (SesException  $e) {
print_r($e->getAwsErrorMessage());
}

注意:我使用的是AWS SDK PHP版本3.67.20

当它失败时,我得到这个错误

AWS HTTP error: Client error: `POST https://email.us-west-2.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): Signature expired: 20181107T003842Z is now earlier than 20181107T005054Z (20181107T005554Z - 5 min.) - <ErrorResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
<Error>
<Type>Sender</Type>
<Code>SignatureDoesNotMatch</Code>
<Message>Signature expired: 20181107T003842Z is now earlier than 20181107T005054Z (20181107T005554Z - 5 min.)</Message>
</Error>
<RequestId>xxxxxxx-xxxx-xxxx-xxxx-13bf5130fec1</RequestId>
</ErrorResponse>

好吧,我找到了解决方案。。。。我已经在服务器中同步了NTP时间,现在它正在工作。我让Ubuntu的链接,所以我遵循https://www.tecklyfe.com/fix-ubuntu-timedatectl-ntp-sync-no/

也许我机器的时钟至少足够同步,不应该每次都出现这个错误。

相关内容

  • 没有找到相关文章

最新更新