From 2691ed7ba1a83c535acd4fe7f0864a279cec3c35 Mon Sep 17 00:00:00 2001 From: Williams Mendez Date: Mon, 19 Feb 2018 09:39:53 -0400 Subject: [PATCH] Fixed #29140 -- Fixed EmailMessage crash when body is None. --- django/core/mail/message.py | 2 +- tests/mail/tests.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/django/core/mail/message.py b/django/core/mail/message.py index 9110fa993b..b25d23881b 100644 --- a/django/core/mail/message.py +++ b/django/core/mail/message.py @@ -231,7 +231,7 @@ class EmailMessage: self.reply_to = [] self.from_email = from_email or settings.DEFAULT_FROM_EMAIL self.subject = subject - self.body = body + self.body = body or '' self.attachments = [] if attachments: for attachment in attachments: diff --git a/tests/mail/tests.py b/tests/mail/tests.py index acce61cf9f..b8d0089ee3 100644 --- a/tests/mail/tests.py +++ b/tests/mail/tests.py @@ -357,6 +357,11 @@ class MailTests(HeadersCheckMixin, SimpleTestCase): msg.attach('example.txt', 'Text file content', 'text/plain') self.assertIn(html_content, msg.message().as_string()) + def test_none_body(self): + msg = EmailMessage('subject', None, 'from@example.com', ['to@example.com']) + self.assertEqual(msg.body, '') + self.assertEqual(msg.message().get_payload(), '') + def test_encoding(self): """ Regression for #12791 - Encode body correctly with other encodings