#26344: EmailMultiAlternatives ignores alternatives when it has attachments and
body is empty
-------------------------------+--------------------
     Reporter:  alvinlindstam  |      Owner:  nobody
         Type:  Uncategorized  |     Status:  new
    Component:  Core (Mail)    |    Version:  1.9
     Severity:  Normal         |   Keywords:
 Triage Stage:  Unreviewed     |  Has patch:  0
Easy pickings:  0              |      UI/UX:  0
-------------------------------+--------------------
 It seems like django.core.mail.EmailMultiAlternatives does not include the
 body or the alternative if the body is falsey and if it has attachments.

 {{{
     >>> from django.core.mail import EmailMultiAlternatives
     >>> m = EmailMultiAlternatives(body="")
     >>> m.attach_alternative("<img
 src='https://example.com/example_image.png'>", "text/html")
     >>> "example_image.png" in m.message().as_string()
     True
     >>> m.attach('example.txt', "example attachment", 'text/plain')
     >>> "example_image.png" in m.message().as_string()
     False
     >>> print(m.message().as_string())
     Content-Type: multipart/mixed;
 boundary="===============2599669765216026223=="
     MIME-Version: 1.0
     Subject:
     From: webmaster@localhost
     To:
     Date: Thu, 10 Mar 2016 14:31:12 -0000
     Message-ID: <[email protected]>

     --===============2599669765216026223==
     MIME-Version: 1.0
     Content-Type: text/plain; charset="utf-8"
     Content-Transfer-Encoding: 7bit
     Content-Disposition: attachment; filename="example.txt"

     example attachment
     --===============2599669765216026223==--

 }}}

 It is probably because of
 
[https://github.com/django/django/blob/53ccffdb8c8e47a4d4304df453d8c79a9be295ab/django/core/mail/message.py#L351
 this] conditional. It checks if body is truthy, even though it is
 sometimes called from EmailMultiAlternatives with a msg that should be
 included.

--
Ticket URL: <https://code.djangoproject.com/ticket/26344>
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/056.b307d94f19e9871108105360db45d0b6%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to