From f5465700a85f34893de6e12302656543f1370254 Mon Sep 17 00:00:00 2001 From: crccheck Date: Thu, 26 Sep 2013 15:07:27 -0500 Subject: [PATCH 1/2] Add: failing test for html only messages --- djrill/tests/test_mandrill_send.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/djrill/tests/test_mandrill_send.py b/djrill/tests/test_mandrill_send.py index b367830..d0c52e0 100644 --- a/djrill/tests/test_mandrill_send.py +++ b/djrill/tests/test_mandrill_send.py @@ -118,6 +118,17 @@ class DjrillBackendTests(DjrillBackendMockAPITestCase): # Don't accidentally send the html part as an attachment: self.assertFalse('attachments' in data['message']) + def test_html_only_message(self): + html_content = '

This is an important message.

' + email = mail.EmailMessage('Subject', html_content, + 'from@example.com', ['to@example.com']) + email.content_subtype = "html" # Main content is now text/html + email.send() + self.assert_mandrill_called("/messages/send.json") + data = self.get_api_call_data() + self.assertNotIn('text', data['message']) + self.assertEqual(data['message']['html'], html_content) + def test_attachments(self): email = mail.EmailMessage('Subject', 'Body goes here', 'from@example.com', ['to1@example.com']) From 393d6e7fa81a1bd0b997aa21038cae228bdb7bcc Mon Sep 17 00:00:00 2001 From: crccheck Date: Thu, 26 Sep 2013 15:32:26 -0500 Subject: [PATCH 2/2] Fix: html messages were sent as text If you followed the instructions at: , djrill would send the body as 'text' instead of 'html', resulting in ugly emails. This also fixes how `[auto_text]` could be set, but couldn't do anything. If you wanted to use `auto_text=True`, you would have to send a null body and then `attach_alternative` your real body. I didn't add a test case for this because they're like... orthogonal..., and gets into behavior testing vs unit testing. [auto_text]: https://djrill.readthedocs.org/en/master/usage/sending_mail/#auto_text --- djrill/mail/backends/djrill.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/djrill/mail/backends/djrill.py b/djrill/mail/backends/djrill.py index 4b39067..0828b37 100644 --- a/djrill/mail/backends/djrill.py +++ b/djrill/mail/backends/djrill.py @@ -112,8 +112,9 @@ class DjrillBackend(BaseEmailBackend): to_list = [{"email": to_email, "name": to_name} for (to_name, to_email) in parsed_rcpts] + content = "html" if message.content_subtype == "html" else "text" msg_dict = { - "text": message.body, + content: message.body, "subject": message.subject, "from_email": from_email, "to": to_list