Merge pull request #45 from texastribune/support-html-alternate-content

Fix: Djrill assumes message content type is text
This commit is contained in:
Mike Edmunds
2013-10-19 11:12:07 -07:00
2 changed files with 13 additions and 1 deletions

View File

@@ -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

View File

@@ -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 = '<p>This is an <strong>important</strong> message.</p>'
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'])