#26802: Sending mails with attachment results in 'bytes' object has no attribute
'encode'
-----------------------------+--------------------------------------
     Reporter:  Brandl       |                    Owner:  nobody
         Type:  Bug          |                   Status:  new
    Component:  Core (Mail)  |                  Version:  1.9
     Severity:  Normal       |               Resolution:
     Keywords:               |             Triage Stage:  Unreviewed
    Has patch:  0            |      Needs documentation:  0
  Needs tests:  0            |  Patch needs improvement:  0
Easy pickings:  0            |                    UI/UX:  0
-----------------------------+--------------------------------------
Changes (by claudep):

 * status:  closed => new
 * resolution:  needsinfo =>


Comment:

 I have been able to reproduce. This happens because post-office attach
 files with binary content (using `FileField.read()`) whatever the mime
 type (see for example how Django distinguish file read mode for text-based
 attachments  in `EmailMessage.attach_file`).

 I have not made my mind yet if and how Django should safeguard against
 such issues...

 Test to reproduce:
 {{{
     def test_attach_text_as_bytes(self):
         msg = EmailMessage('subject', 'body', '[email protected]',
 ['[email protected]'])
         file_path = os.path.join(os.path.dirname(upath(__file__)),
 'attachments', 'file.txt')
         with open(file_path, mode='rb') as fh:
             msg.attach('file.txt', fh.read())
         msg.send()
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26802#comment:5>
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/064.3a31e3259eff6937fa26fc852f48aa5a%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to