{{{
>>> 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: <2016031014311...@236.1.168.192.in-addr.arpa>
--===============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.
* needs_better_patch: => 0
* needs_docs: => 0
* type: Uncategorized => Bug
* needs_tests: => 0
* stage: Unreviewed => Accepted
Comment:
I haven't completely verified the report to say what the proper solution
should be, however, the `if self.body` check was introduced in
2d082a34dc61a832710d98a933858fd2c0059644 without any tests, so at least
some test should be added to demonstrate what it accomplishes (if
anything).
--
Ticket URL: <https://code.djangoproject.com/ticket/26344#comment:1>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/8983 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/26344#comment:2>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/26344#comment:3>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"af35c69a3c595ff77188ff0d7dac6ab747484ac3" af35c69a]:
{{{
#!CommitTicketReference repository=""
revision="af35c69a3c595ff77188ff0d7dac6ab747484ac3"
Fixed #26344 -- Made EmailMessage include alternatives when the body is
empty and it has attachments.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26344#comment:4>