diff --git a/AUTHORS.txt b/AUTHORS.txt index ccb7bc9..5ab90fc 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -15,3 +15,4 @@ Eric Hennings Michael Hobbs Sameer Al-Sakran Kyle Gibson +nikolay-saskovets diff --git a/djrill/mail/backends/djrill.py b/djrill/mail/backends/djrill.py index 6ddc7ce..9e31917 100644 --- a/djrill/mail/backends/djrill.py +++ b/djrill/mail/backends/djrill.py @@ -144,12 +144,16 @@ class DjrillBackend(BaseEmailBackend): content = "html" if message.content_subtype == "html" else "text" msg_dict = { content: message.body, - "subject": message.subject, - "from_email": from_email, "to": to_list } - if from_name: - msg_dict["from_name"] = from_name + + if not getattr(message, 'use_template_from', False): + msg_dict["from_email"] = from_email + if from_name: + msg_dict["from_name"] = from_name + + if not getattr(message, 'use_template_subject', False): + msg_dict["subject"] = message.subject if message.extra_headers: msg_dict["headers"] = message.extra_headers diff --git a/djrill/tests/test_mandrill_send_template.py b/djrill/tests/test_mandrill_send_template.py index ed987b9..45b7416 100644 --- a/djrill/tests/test_mandrill_send_template.py +++ b/djrill/tests/test_mandrill_send_template.py @@ -27,6 +27,29 @@ class DjrillMandrillSendTemplateTests(DjrillBackendMockAPITestCase): 'content': "
Half off all fruit
"} ] ) + def test_send_template_without_from_field(self): + msg = mail.EmailMessage('Subject', 'Text Body', + 'from@example.com', ['to@example.com']) + msg.template_name = "PERSONALIZED_SPECIALS" + msg.use_template_from = True + msg.send() + self.assert_mandrill_called("/messages/send-template.json") + data = self.get_api_call_data() + self.assertEqual(data['template_name'], "PERSONALIZED_SPECIALS") + self.assertFalse('from_email' in data['message']) + self.assertFalse('from_name' in data['message']) + + def test_send_template_without_subject_field(self): + msg = mail.EmailMessage('Subject', 'Text Body', + 'from@example.com', ['to@example.com']) + msg.template_name = "PERSONALIZED_SPECIALS" + msg.use_template_subject = True + msg.send() + self.assert_mandrill_called("/messages/send-template.json") + data = self.get_api_call_data() + self.assertEqual(data['template_name'], "PERSONALIZED_SPECIALS") + self.assertFalse('subject' in data['message']) + def test_no_template_content(self): # Just a template, without any template_content to be merged msg = mail.EmailMessage('Subject', 'Text Body', diff --git a/docs/usage/templates.rst b/docs/usage/templates.rst index 8b9acfc..c4b4b5e 100644 --- a/docs/usage/templates.rst +++ b/docs/usage/templates.rst @@ -37,6 +37,33 @@ and will ignore any `body` text set on the `EmailMessage`. All of Djrill's other :ref:`Mandrill-specific options