#19186: fail send utf-8 email
-----------------------------------+------------------------------------
     Reporter:  alex_po            |                    Owner:  nobody
         Type:  Bug                |                   Status:  new
    Component:  Core (Mail)        |                  Version:  master
     Severity:  Normal             |               Resolution:
     Keywords:  mail utf8 python3  |             Triage Stage:  Accepted
    Has patch:  0                  |      Needs documentation:  0
  Needs tests:  0                  |  Patch needs improvement:  0
Easy pickings:  0                  |                    UI/UX:  0
-----------------------------------+------------------------------------
Changes (by lukeplant):

 * keywords:  mail, utf8 => mail utf8 python3
 * needs_docs:   => 0
 * needs_better_patch:   => 0
 * needs_tests:   => 0
 * stage:  Unreviewed => Accepted


Comment:

 I haven't fully reproduced it, but can confirm that
 `EmailMessage.message().as_string` is returning a unicode object not a
 bytestring object, on Python 3.2 and 3.3, as follows.

 {{{
 >>> EmailMessage('тест', 'тест', '[email protected]',
 ['[email protected]']).message().as_string()
 }}}

 On Python 2 it is returning a bytestring, and I think that smtplib is
 expecting a bytestring, hence the problem.

 Logically, this method ought to produce a bytestring, since it applies the
 encoding specified and returns a series of bytes fir for sending over the
 network (which includes in it a declaration of the charset).

 However, our `SafeMIMEText` class that is doing this inherits from the
 stdlib `MIMEText` class, and it follows the implementation of `MIMEText`.
 `MIMEText.as_string()` also produces a unicode string under Python 3. This
 seems crazy to me, since the entire job of `MIMEText` is to encode the
 input data as an email message ready to be sent over SMTP. But it's
 difficult to believe they did this without thought.

 It may be that we are not supposed to be using the `as_string()` method to
 render to a string. But it's not clear what we should be using.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/19186#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to