django-ses / django-ses Goto Github PK
View Code? Open in Web Editor NEWA Django email backend for Amazon's Simple Email Service
Home Page: http://hmarr.com/2011/jan/26/using-amazons-simple-email-service-ses-with-django/
License: MIT License
A Django email backend for Amazon's Simple Email Service
Home Page: http://hmarr.com/2011/jan/26/using-amazons-simple-email-service-ses-with-django/
License: MIT License
Does anybody know if it's compatible with django-newsletter?
Thanks!
am firing up a celery task that sends out emails to users, the task though is failing to send and below is the console output
[2012-11-13 11:45:28,103: DEBUG/MainProcess] Method: POST
[2012-11-13 11:45:28,107: DEBUG/MainProcess] Path: /
[2012-11-13 11:45:28,107: DEBUG/MainProcess] Data: Action=GetSendQuota
[2012-11-13 11:45:28,107: DEBUG/MainProcess] Headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}
[2012-11-13 11:45:28,109: DEBUG/MainProcess] Host: email-smtp.us-east-1.amazonaws.com
[2012-11-13 11:45:28,109: DEBUG/MainProcess] establishing HTTPS connection: host=email-smtp.us-east-1.amazonaws.com, kwargs={}
[2012-11-13 11:45:28,109: DEBUG/MainProcess] Token: None
[2012-11-13 11:45:28,702: DEBUG/MainProcess] wrapping ssl socket; CA certificate file=/home/mo/projects/garageenv/local/lib/python2.7/site-packages/boto/cacerts/cacerts.txt
[2012-11-13 11:45:29,385: DEBUG/MainProcess] validating server certificate: hostname=email-smtp.us-east-1.amazonaws.com, certificate hosts=[u'email-smtp.us-east-1.amazonaws.com']
[2012-11-13 11:45:39,618: ERROR/MainProcess] :1:0: syntax error
First, love this package great work!
I'd love to an update for Boto3 ( https://aws.amazon.com/blogs/aws/now-available-aws-sdk-for-python-3-boto3/ ) as it's encouraged to become the starting point for new projects.
Thanks!
./manage.py ses_email_address
/usr/local/creatarr/lib/python2.6/site-packages/registration/models.py:4: DeprecationWarning: the sha module is deprecated; use the hashlib module instead
import sha
Traceback (most recent call last):
File "./manage.py", line 11, in
execute_manager(settings)
File "/usr/local/creatarr/lib/python2.6/site-packages/django/core/management/init.py", line 438, in execute_manager
utility.execute()
File "/usr/local/creatarr/lib/python2.6/site-packages/django/core/management/init.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/creatarr/lib/python2.6/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(_args, *_options.dict)
File "/usr/local/creatarr/lib/python2.6/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(_args, *_options)
File "/usr/local/creatarr/lib/python2.6/site-packages/django_ses/management/commands/ses_email_address.py", line 35, in handle
SESConnection.DefaultHost)
AttributeError: type object 'SESConnection' has no attribute 'DefaultHost'
Pypi version is a year and a half out of date. Looks like there have been lots of changes since then.
Would be nice to be able to pass profile_name
into SESConnection, such that multiple boto installations could be used from the same machine.
conn = connection.SESConnection(aws_access_key_id=settings.AWS_ACCESS_KEY_ID, aws_secret_access_key=settings.AWS_SECRET_ACCESS_KEY, profile_name=settings.BOTO_PROFILE_NAME)
I'm going to roll a v0.3 release once I can verify that the tests do indeed pass, but want to bring it up that the tag was made in January by the package on PyPI was created last November.
Hi,
Thanks so much for this great package! I've used it on a couple of sites and it works like a charm.
My client wants me to use the smtp version of ses - is there any way to do that with this package?
Thanks!
Not sure if you count this as a bug or not.
My emails started to fail after using this backend because the headers dictionary I was passing in had the status, message_id and header_id written into it when sent. I reused this dictionary for subsequent emails so it failed after the first message was sent.
It's easy to work around by creating a new dictionary when sending each email rather than reusing it but it might be good to note this in the readme?
It may be helpful to note in the documentation that DEFAULT_FROM_EMAIL should be explicitly set in your settings.py if you want to take advantage of built-in views that send mail. It's a PITA gotcha.
GAE doesn't support validate certs, I presume because it uses its own url fetching service. Therefore, either disable it on GAE, or expose a configuration setting to disable it.
This needs to be done creating the SESConnection object.
Hi,
Thank you for your piece of software, i'm using it production and it's so simple.
BTW, today i had to upgrade django-ses in order to stay up-to-date with my requirements, and i noticed that django-ses installed django==1.2.5 within. This is quite dangerous because it may breaks lot of sites - not all sites have migrated to 1.2.5, which implies to modify AJAX script in order to handle CSRF.
Can you remove this dependency, please ?
Cheers.
Should django be listed in requirements section of the docs? And if so, which versions are we supporting? I have only tried this on 1.3.
pydkim
hasn't been updated since 2008. The author recently updated his website suggesting that people use the the actively maintained fork dkimpy
NOTE: This page describes the last release of pydkim from 2008. The latest version is a fork found at dkimpy in Launchpad and is under active development.
https://pypi.python.org/pypi/dkimpy
I noticed this because pip was complaining the pydkim didn't have a secure/verifiable version available for download.
Probably should update the docs to have people use the actively maintained fork instead...
0.7.1 is listed on pypi: https://pypi.python.org/pypi/django-ses/0.7.1 for a few weeks now.
I tried installing it with python 3.5 on ubuntu, using pip 8.1.1 but I keep getting this error:
Could not find a version that satisfies the requirement django-ses==0.7.1 (from versions: 0.1, 0.2, 0.3.0, 0.4.0, 0.4.1, 0.6.0, 0.7.0)
I tried --no-cache-dir and then just removing ~/.cache/pip altogether. I also tried installing on a few other machines but none of their pip's can see 0.7.1.
Hi guys,
Is it possible to make this package support "IAM roles for EC2" feature?
I think the workable change would be something like below:
_Orginal_
connection = SESConnection(
aws_access_key_id=access_key_id,
aws_secret_access_key=access_key,
region=region)
_Support for IAM_
connection = boto.ses.connect_to_region(region=region) If aws_access_key_id is None or aws_secret_access_key is None else boto.ses.connect_to_region(aws_access_key_id=access_key_id, aws_secret_access_key=access_key, region=region)
SESBackend.send_messages use timedelta.total_seconds() when calculating the rate throttling delay (line 142 of django_ses.init.py in the current PyPI package). This method is new in Python 2.7, so I am getting AttributeError under Python 2.6. How about doing the calculation that total_seconds() does instead of using the shortcut? The calculation is in the Python docs:
http://docs.python.org/library/datetime.html#datetime.timedelta.total_seconds
timedelta.total_seconds()
Return the total number of seconds contained in the duration. Equivalent to (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6 computed with true division enabled.
Note that for very large time intervals (greater than 270 years on most platforms) this method will lose microsecond accuracy.
New in version 2.7.
Firstly, AWS sets message-id to its own value, so whatever it receives from client is unimportant, as explained here: https://forums.aws.amazon.com/message.jspa?messageID=262855
However, if you do not set it explicitly to something when calling message.message() in send_messages(), then Django will try to set it based on socket connection which fails on Google App Engine (since GAE only support http/https requests).
Therefore, to work on GAE, it should be set explicitly, which, again, is okay since AWS uses its own value.
Getting this error when sending an email. Django 1.9.2, Python 3.5.1
I've seen this mentioned in a few other places, but I though I'd raise a specific issue for it. Could a PyPi release be done for the project? I'm currently pulling in from GitHub in order to get Python 3 support.
Am I right in thinking @pcraciunoiu has permission to do this?
According to FAQ #39 in order to change where bounce messages are sent you have to change the source parameter. That's why I came up with this patch that allows you to change the source parameter, https://gist.github.com/1105465.
Example Usage:
msg = EmailMultiAlternatives(subject, message_text, from_email, [to]) msg.attach_alternative(message_html, "text/html") msg.return_path = '[email protected]' # The address I want the bounce message to go to msg.send()
Hi
Can you also please update the documentation that django-ses has a built-in endpoint for amazon SNS notifications
Thanks
Bala
Here's an example of how it's done: https://github.com/django-nonrel/djangoappengine/blob/develop/djangoappengine/mail.py
It will be good also handle the "Delivery Notifications" which will be useful for statistics
I just had an unusual 500 error from SES with this response:
<ErrorResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
<Error>
<Type>Receiver</Type>
<Code>InternalFailure</Code>
<Message>An internal failure has occurred.</Message>
</Error>
<RequestId>2e7d4c8d-3746-11e5-a140-b919bcc9ecab</RequestId>
</ErrorResponse>
Normally, when an error occurs, my server has logic to queue a task to retry the message later. But, on each subsequent retry, I got this error:
File "/base/data/home/apps/s~f/1.386013588458176163/django_ses/mail.py", line 35, in _send_deferred
backend.send_messages([message])
File "/base/data/home/apps/s~f/1.386013588458176163/django_ses/mail.py", line 203, in send_messages
raw_message=unicode(dkim_sign(message.message().as_string()), 'utf-8')
File "/base/data/home/apps/s~f/1.386013588458176163/django/core/mail/message.py", line 260, in message
msg[name] = value
File "/base/data/home/apps/s~fare/1.386013588458176163/django/core/mail/message.py", line 190, in __setitem__
name, val = forbid_multi_line_headers(name, val, self.encoding)
File "/base/data/home/apps/s~fare-clock/1.386013588458176163/django/core/mail/message.py", line 86, in forbid_multi_line_headers
raise BadHeaderError("Header values can't contain newlines (got %r for header %r)" % (val, name))
BadHeaderError: Header values can't contain newlines (got u'<ErrorResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">\n <Error>\n <Type>Receiver</Type>\n <Code>InternalFailure</Code>\n <Message>An internal failure has occurred.</Message>\n </Error>\n <RequestId>2e7d4c8d-3746-11e5-a140-b919bcc9ecab</RequestId>\n</ErrorResponse>\n' for header 'body')
What's strange is it looks like the message had a header containing the error response from the original attempt to send the message. I looked through the code, and noticed that the exception handler in send_messages() looks like this:
except SESConnection.ResponseError as err:
# Store failure information so to post process it if required
error_keys = ['status', 'reason', 'body', 'request_id',
'error_code', 'error_message']
for key in error_keys:
message.extra_headers[key] = getattr(err, key, None)
if not self.fail_silently:
raise
So it's storing the error as a message header, and sending it in the subsequent retry. Is it wrong to retry a message, or is this a bug?
Trying to access the dashboard view from django_ses.urls causes TemplateDoesNotExist when django-ses is installed using pip, because django_ses/templates/django_ses/send_stats.html is missing from the package.
I find this rather confusing. Am I missing something?
Hi,
I am trying to configure SQL Database mail through Amazon Simple Email Service. I have verified the email address. The "To", "From" and "Reply To" email addresses are the same mail address which i have verified.
This is the log message i receive when i try to test mail through database mail. I have already verified the email addresses in management console. Also both the "From" address and "To" address are the same verified email address.
Date 8/21/2012 12:25:18 PM
Log Database Mail (Database Mail Log)
Log ID 102
Process ID 2952
Mail Item ID 28
Last Modified 8/21/2012 12:25:18 PM
Last Modified By sa
Message
The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 2 (2012-08-21T12:25:18). Exception Message: Cannot send mails to mail server. (Transaction failed. The server response was: Message rejected: Email address is not verified.).
)
So it would be more simple to extend the backend for modifying raw message and sender options, eg, to dkim sign messages:
http://djangosnippets.org/snippets/1995/
Currently there's no documentation on how to setup the dashboard view.
EDIT: Sorry but I mean better documentation like example of how it should be done in urls.py
Interested if there is support for Python 3
and Django 1.7
?
If I bump to boto 2.1.0 django_ses breaks:
>>> from django.core.mail import send_mail
>>> send_mail('subject', 'message', '[email protected]', ['[email protected]'])
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/opt/virtualenvs/proj/src/django/django/core/mail/__init__.py", line 59, in send_mail
fail_silently=fail_silently)
File "/opt/virtualenvs/proj/src/django/django/core/mail/__init__.py", line 41, in get_connection
return klass(fail_silently=fail_silently, **kwds)
File "/opt/virtualenvs/proj/lib/python2.6/site-packages/django_ses/__init__.py", line 22, in __init__
SESConnection.DefaultHost)
AttributeError: type object 'SESConnection' has no attribute 'DefaultHost'
>>> import boto
>>> boto.__version__
'2.1.0'
>>> import django_ses
>>> django_ses.__version__
'0.2'
Does this support Django 1.8. I have not seen anything related to that. Do you have any plans to add the support, if yes when it will be up.
Thanks.
Error using Python 2.7:
if len(new_send_times) > rate_limit * window * self._throttle:
TypeError: can't multiply sequence by non-int of type 'float'
In case anyone ever gets this random unhelpful error:
Traceback (most recent call last):
....
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/sax/handler.py", line 38, in fatalError
raise exception xml.sax._exceptions.SAXParseException: <unknown>:1:0: syntax error
It's because you've set the AWS_SES_REGION_ENDPOINT incorrectly. As of today, the correct setting is:
AWS_SES_REGION_ENDPOINT = 'email.us-east-1.amazonaws.com'
Don't use the SMTP server setting set in the AWS dashboard.
I am using django-ses and the object in not creating at admin site
Application database is MySQL, configured with UTF8 (utf8_general_ci).
While trying to send emails with data from the database and using django templates (render_to_string) I get this exception:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 336: ordinal not in range(128)
In order to fix it, I had to monkey patch boto/ses/connection.py to use Django's smart_unicode on line 299.
But probably problems are arising from this line https://github.com/hmarr/django-ses/blob/master/django_ses/__init__.py#L156
I have verified my from address, and also i have production access, but still i am unable to send mail to an unverified email address.
There is support for python 3.3, but not for Python 3.4!
Anyone else?
Installing the latest version (0.2.0) results in a package name of:
django-ses-.join-str-x-.for.x.in.VERSION-
The following change in setup.py fixes the problem:
VERSION = '.'.join(version_line.split(' = ')[-1][1:-2].split(', '))
I am using Django 1.9 and Python 3. When runserver:
File "/Users/abc/.virtualenvs/project/lib/python3.4/site-packages/django_ses/init.py", line 173
except SESConnection.ResponseError, err:
^
SyntaxError: invalid syntax
http://sesblog.amazon.com/blog/tag/Throttle
Anyway, regarding what happens when you hit your limits during a call to send to multiple recipients – first remember that normally, sending limits are based on recipients rather than on messages. For example, an email to five recipients counts as five against your daily sending quota. When you send to multiple recipients, though, if you have any emails remaining in your daily sending quota, then your API call (as long as other factors are ok, like none of the addresses are on the blacklist) will go through. Keep in mind however that the amount you have left in your daily sending quota is being continuously calculated by Amazon SES, so it’s not good to be hovering too close to this limit. If you find yourself frequently cutting it this close, submit an Extended Access Request.
It’s a similar story with your send rate quota – if, at the rate you are sending, you have any emails left in your send rate quota, you can send to multiple recipients. However, you will not be able to send further emails until you have built up enough quota again. For example, if your send rate quota is one message per second, and you send a message to five recipients at once, Amazon SES lets you do that. For the next five seconds, though, Amazon will return errors for all send attempts. Once five seconds have passed, you'll have available quota and you will be able to send again. This way, emails with many recipients can get through, and they’ll get through at the overall rate allowed by the quota.
I had this message:
<Code>Throttling</Code>
<Message>Maximum sending rate exceeded.</Message>
You need to consider number of recipients for every message.
I can propose this:
n_recipients = len(set(previous_message.recipients()))
additional_delay = 1000 / rate_limit * (n_recipients - 1)
It adds 1/rate_limit seconds for every additional recipient. If there is only one, additional_delay is 0.
Hi
How do we get the individual statistics like bounced/opened/spam reported of each email sent
Thanks
Get Stats management command should use AWS_REGION_NAME from settings file.
I see that this app does not include the initial migrations. Is this intentional or am I missing something here?
I am using django-ses:
Please find settings for it
EMAIL_BACKEND = 'django_ses.SESBackend'
EMAIL_HOST = 'email.us-east-1.amazonaws.com'
EMAIL_PORT = 465
EMAIL_HOST_USER = '----------------'
EMAIL_HOST_PASSWORD = '-------------------'
AWS_ACCESS_KEY_ID = '-------------------'
AWS_SECRET_ACCESS_KEY = '------------------------------'
AWS_SES_REGION_ENDPOINT = 'email.us-east-1.amazonaws.com'
Find the error stack:
BotoServerError: BotoServerError: 403 Forbidden
<ErrorResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
<Error>
<Type>Sender</Type>
<Code>AccessDenied</Code>
<Message>User: arn:aws:iam::00000000000:user/ses-smtp-user.20160209-000000 is not authorized to perform: ses:GetSendQuota</Message>
</Error>
<RequestId>0000000-0000-0000-0000-0000000000</RequestId>
</ErrorResponse>
SES allows you to handle bounced email messages via the SNS which can ping a URL with the JSON data.
I'd like a view that can handle the bounced data, save the info in the DB and fire a signal when a bounced message is recieved.
See: http://docs.amazonwebservices.com/ses/latest/DeveloperGuide/NotificationsViaSNS.html
Django 1.2 added lots of support for custom views in the model admin. The statistics views should be implemented using the model admin and use the permissions settings associated with that model.
TBH, I'm not sure where this bug is coming from, Boto, SES or my own configuration.
Here it is though:
BotoServerError at /accounts/signup/
BotoServerError: 400 Bad Request
Sender
MessageRejected
Email address is not verified.
9360bdd6-c549-11e0-82fb-b9b4121fdb69
$ ./manage.py ses_email_address -l
Fetching list of verified emails:
[email protected]
Settings.py:
EMAIL_BACKEND = 'django_ses.SESBackend'
EMAIL_FROM = '[email protected]'
EMAIL_HOST_USER='[email protected]'
DEFAULT_FROM_EMAIL='[email protected]'
SERVER_EMAIL='[email protected]'
Went through the notification confirmation email from Amazon.. so why the rejected message?
The sending of mails is done using Boto's ses.connection.send_raw_mail function and this is a dog's breakfast to use when trying to send HTML emails with a plain text version (if it's even possible). If it is practical for where this project is going, exposing the ses.connection.send_mail function would be be immensely useful to get SES functionality with Django SES reporting functionality (as well as a better expression of SES functionality as a service).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.