Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#28196 closed Bug (invalid)

Character Encoding on EmailMessage when sending

Reported by: Helmut Owned by: nobody
Component: Core (Mail) Version: 1.11
Severity: Normal Keywords: emailmessage, send, email, unicode
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I'm not 100% sure if this is bug, or whether my understand of unicode is wrong. Nevertheless Django 1.11 behaves differently than 1.10.7. Using Django 1.10.7, if I send an Email using EmailMessage, but I encode the subject and body with UTF-8, it sends successfully. For example:

email = EmailMessage("asd’asd".encode("utf-8"), "asd’asd".encode("utf-8"), "blah@foo.com", ["yup@yadda.com"])
email.send()

But if I run the same code in Django 1.11, it throws an exception because of the unicode character that was used:
'ascii' codec can't decode byte 0xe2 in position 92: ordinal not in range(128)

So, might there be a bug in 1.11, or should I not be using the ".encode"? (Was using that because of weird user input)

And furthermore, why does pre-1.11 not throw an exception?

I thank you for you attention.

Change History (4)

comment:1 Changed 5 years ago by Tim Graham

Component: UncategorizedCore (Mail)

To help answer your question, you could bisect to find the commit where the behavior changed.

Generally, you should use our support channels to ask "is it a bug?" questions rather than seeking help through the ticket tracker.

comment:2 Changed 5 years ago by Claude Paroz

There's absolutely no reason to encode the content passed to EmailMessage, so even if it was not failing before, I would be against restoring the previous behavior.
Nonetheless the EmailMessage __init__ docstring talks about accepting UTF-8 bytestrings, which should be removed IMO.
Unless someone comes with a compelling use case to allow bytestrings for EmailMessage subject and body. Binary content should be left for attachments.

comment:3 Changed 5 years ago by Helmut

Resolution: invalid
Status: newclosed

comment:4 Changed 5 years ago by Claude Paroz <claude@…>

In d4d812c:

Refs #28196 -- Removed mentions of bytestrings for EmailMessage

With Python 3, there are no more reasons to special-case EmailMessage
arguments which should be plain strings.

Note: See TracTickets for help on using tickets.
Back to Top