sklarsa / django-sendgrid-v5

An implementation of Django's EmailBackend compatible with sendgrid-python v5+
MIT License
323 stars 54 forks source link

Handle cases where Django 1.11 converts attachment content to unicode #36

Closed kronion closed 6 years ago

kronion commented 6 years ago

Django 1.11+ converts the content of email attachments to unicode if the attachment content type is text/*. See https://github.com/django/django/blob/stable/1.11.x/django/core/mail/message.py#L379. For Python2 applications, this library was trying to re-encode the content as if it was ascii, which would error on unicode characters.

Explicitly encode utf-8, rather than relying on the Python default encoding. Also add a test case.