Reputation: 4710
from datetime import datetime as dt, timedelta, date
from django.conf import settings
from django.core.mail import send_mail
from django.core.mail import EmailMultiAlternatives
from django.core.management.base import BaseCommand, CommandError
from hive.apps.accounts.sms_utils import send_sms_twilio
to_email = ['[email protected]']
subject = 'Your subject here'
email_body = 'The following clients are currently eligible for Test.Please contact them .<br>'
msg = EmailMultiAlternatives(subject, '', settings.DEFAULT_FROM_EMAIL, to_email)
msg.attach_alternative(email_body, "text/html")
msg.send()
When i run this code on centos with AWS instance.i am getting following error
BotoServerError: 400 Bad Request
<ErrorResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
<Error>
<Type>Sender</Type>
<Code>RequestExpired</Code>
<Message>Request timestamp: Wed, 01 Oct 2014 07:35:22 GMT expired. It must be within 300 secs/ of server time.</Message>
</Error>
<RequestId>c79a9723-493c-11e4-b2d8-51a7cb197196</RequestId>
</ErrorResponse>
while its working on another AWS instance.
I have Tested following possibilities.
Upvotes: 2
Views: 1508
Reputation: 5047
In my case my Ubuntu server was out of synchronization with SES backend and returned me the same message. To solve it:
wget -S "https://email.eu-west-1.amazonaws.com"
Change the link depending on you email endpoint.Check time on your server with date
If they are different install ntp on server with sudo apt-get install ntp
And finally syncronize your server time:
sudo service ntp stop
sudo ntpdate -s time.nist.gov
sudo service ntp start
Upvotes: 0
Reputation: 136
That error indicates your server time isn't synced with Amazon's server's time...
you can check the time of Amazon's server by running:
wget -S "https://email.us-east-1.amazonaws.com"
look for the timestamp in the returned message. replace us-east-1 with your appropriate regional endpoint.
Compare that to your system's time...
if you need an NTP server, you can use:
0.amazon.pool.ntp.org
1.amazon.pool.ntp.org
2.amazon.pool.ntp.org
3.amazon.pool.ntp.org
if this is in one of your own Amazon VPCs, you can set a DHCP option set on the VPC with those ntp servers specified. If your server still isn't syncing, make sure you don't have a security group blocking ntp (UDP 123).
Upvotes: 1