Coder Social home page Coder Social logo

django-ses / django-ses Goto Github PK

View Code? Open in Web Editor NEW
987.0 19.0 223.0 550 KB

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

Python 94.90% HTML 5.10%

django-ses's Issues

Unable to send out emails getting <unknown>:1:0: syntax error

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

ses_email_address raises exception

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

update pypi

Pypi version is a year and a half out of date. Looks like there have been lots of changes since then.

Passing profile_name into SESConnection

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)

PyPI v0.2 and Github tag v0.2 don't match

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.

Request: Support for SES SMTP

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!

django_ses.SESBackend writes to email headers

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?

Clarify documentation for use with built-in views

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.

Configure travis-ci integration

Now that PR #33 is merged, django-ses can be tested against the Travis CI community-driven continuous integration server. It requires some configuration by the project admin, however. I have this turned on for my fork, but it'd be great if this main repository had it as well.

Remove django from required package

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.

Django version to support

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.

Need to update docs to point to new pydkim location

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://launchpad.net/dkimpy

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 doesn't show-up nor install in pip

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.

Support for "IAM roles for EC2"

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)

Support Python 2.6

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.

Set message-id to fixed value before sending, or else will break on Google App Engine

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.

PyPi Release

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?

No way to change the return-path/source

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()

Documentation Update required

Hi

Can you also please update the documentation that django-ses has a built-in endpoint for amazon SNS notifications

Thanks
Bala

Retry error

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?

django-ses-0.2.tar.gz @ pypi is missing the templates dir

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?

Email address is not verified - SQL Database and Amazon SES error

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.).
)

Document how to setup SES dashboard

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

broken with boto 2.1.0

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'

Support for Django 1.8

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.

Documentation addition: Troubleshooting SAX issue.

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.

Problems with utf8 from MySQL, UnicodeDecodeError exception thrown for emails with content from db.

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

Version calculation in setup.py isn't correct

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(', '))

Throttling bug on multiple recipients

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.

Missing migrations

I see that this app does not include the initial migrations. Is this intentional or am I missing something here?

django ses issue (with celery): BotoServerError: BotoServerError: 403 Forbidden

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>

Views should be implemented using admin views

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.

"Email address is not verified" for verified email

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?

Boto send_mail is unsupported

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).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.