Reputation: 11
I have a recent issue with my emails, on week ago I started get errors in my email sending, problem is that sometimes when I call this function sendEmail
it never returns the Aws/Result
or any Exception
. So my script is looped waited for it. The issue is sporadic. I supposes that my requested couldn't be added to AWS queue but I would get an Exception at least.
I tried to find a timeout setting that I could set to don't eternally wait, but I couldn't find it in documentation. I have 2 years using this service and I haven't get error until now.
Somebody else has experienced this issue?
Where can I set a timeout for this calls related to SES Class?
Simple code:
use Aws\Ses\SesClient;
use Aws\Ses\Exception\SesException;
// Replace [email protected] with your "From" address.
// This address must be verified with Amazon SES.
define('SENDER', 'sender@example');
// Replace [email protected] with a "To" address. If your account
// is still in the sandbox, this address must be verified.
define('RECIPIENT', '[email protected]');
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());
}
Note: I'm using AWS SDK PHP version 3.67.20
When it fails, I'm getting this error
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>
Upvotes: 0
Views: 978
Reputation: 11
Well, I found the solution.... I have synchronized NTP Time in my server and now it's working. I let the link for Ubuntu SO that I followed https://www.tecklyfe.com/fix-ubuntu-timedatectl-ntp-sync-no/
Maybe my machine's clock was at least sufficiently in sync that this error shouldn't came up every time.
Upvotes: 1