【问题标题】:No response from AWS SES when I try to send an email当我尝试发送电子邮件时,AWS SES 没有响应
【发布时间】:2019-04-10 05:24:36
【问题描述】:

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

我试图找到一个可以设置为不永远等待的超时设置,但我在文档中找不到它。我有 2 年使用此服务,直到现在我还没有收到错误。

其他人遇到过这个问题吗?

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

简单代码:

use Aws\Ses\SesClient;
use Aws\Ses\Exception\SesException;

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

【问题讨论】:

    标签: amazon-web-services amazon-ses aws-php-sdk


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2019-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-05-23
      • 2019-03-23
      • 2011-08-07
      • 2020-10-20
      • 2017-11-11
      相关资源
      最近更新 更多