pmclanahan / django-celery-email

A Django email backend that uses a celery task for sending the email.
BSD 3-Clause "New" or "Revised" License
477 stars 108 forks source link

Support Celery's JSON serializer #5

Closed daxtens closed 9 years ago

daxtens commented 10 years ago

This supports the use of Celery's JSON serializer, which improves the security of Celery.

Prior to this patch, attempting to use Celery with the JSON serialization (as opposed to pickling) generated error messages complaining that a django.core.mail.EmailMessage is not JSON serializable. This patch converts email messages to dictionaries which are JSON serializable.

For those still using the pickle serializer, everything should continue to work the same.

Caveat on JSON-serializing attachments

This patch copies the attachments property of EmailMessages without further processing. Per [https://docs.djangoproject.com/en/dev/topics/email/#emailmessage-objects](the Django docs on EmailMessage objects), attachments are:

either email.MIMEBase.MIMEBase instances, or (filename, content, mimetype) triples.

As I understand it, this means that attachments as MIMEBase instances will still fail, but the triples may succeed. My application doesn't send attachments at the moment, so I haven't tested this. If in the deep distant future I get the opportunity to test it I will extend the patch.

Attachments will still work for those using pickling. In the mean time, this patch still enhances support for those using JSON - instead of everything failing, only a limited subset of things fail.

zcho commented 10 years ago

need this!

jairtrejo commented 10 years ago

:+1:

daxtens commented 10 years ago

I've just added couple of small updates with differences I missed regarding dicts vs objs - thanks @japsu.

zcho commented 10 years ago

Thanks! want to see in the master branch

maryokhin commented 10 years ago

Please merge this, because Celery advocates to not using Pickle anymore (for safety reasons), and it breaks when using JSON

maryokhin commented 9 years ago

@pmclanahan bugging you again to merge this

pmclanahan commented 9 years ago

Wow! Thanks for the ping. Somehow I apparently had my notifications messed up and I never saw this. I'm so sorry everyone! I've been a horrible maintainer. I'll get this merged and cut a new release today.