mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 11:51:05 -05:00
Allow all extra message headers in send.
Mandrill has relaxed previous API restrictions on headers. Fixes #58.
This commit is contained in:
@@ -130,8 +130,7 @@ class DjrillBackend(BaseEmailBackend):
|
||||
still work through Mandrill.
|
||||
|
||||
Raises NotSupportedByMandrillError for any standard EmailMessage
|
||||
features that cannot be accurately communicated to Mandrill
|
||||
(e.g., prohibited headers).
|
||||
features that cannot be accurately communicated to Mandrill.
|
||||
"""
|
||||
sender = sanitize_address(message.from_email, message.encoding)
|
||||
from_name, from_email = parseaddr(sender)
|
||||
@@ -162,11 +161,6 @@ class DjrillBackend(BaseEmailBackend):
|
||||
% len(message.bcc))
|
||||
|
||||
if message.extra_headers:
|
||||
for k in message.extra_headers.keys():
|
||||
if k != "Reply-To" and not k.startswith("X-"):
|
||||
raise NotSupportedByMandrillError(
|
||||
"Invalid message header '%s' - Mandrill "
|
||||
"only allows Reply-To and X-* headers" % k)
|
||||
msg_dict["headers"] = message.extra_headers
|
||||
|
||||
return msg_dict
|
||||
|
||||
@@ -86,7 +86,8 @@ class DjrillBackendTests(DjrillBackendMockAPITestCase):
|
||||
bcc=['bcc@example.com'],
|
||||
cc=['cc1@example.com', 'Also CC <cc2@example.com>'],
|
||||
headers={'Reply-To': 'another@example.com',
|
||||
'X-MyHeader': 'my value'})
|
||||
'X-MyHeader': 'my value',
|
||||
'Message-ID': 'mycustommsgid@example.com'})
|
||||
email.send()
|
||||
self.assert_mandrill_called("/messages/send.json")
|
||||
data = self.get_api_call_data()
|
||||
@@ -94,7 +95,9 @@ class DjrillBackendTests(DjrillBackendMockAPITestCase):
|
||||
self.assertEqual(data['message']['text'], "Body goes here")
|
||||
self.assertEqual(data['message']['from_email'], "from@example.com")
|
||||
self.assertEqual(data['message']['headers'],
|
||||
{ 'Reply-To': 'another@example.com', 'X-MyHeader': 'my value' })
|
||||
{'Reply-To': 'another@example.com',
|
||||
'X-MyHeader': 'my value',
|
||||
'Message-ID': 'mycustommsgid@example.com'})
|
||||
# Mandrill doesn't have a notion of cc.
|
||||
# Djrill just treats cc as additional "to" addresses,
|
||||
# which may or may not be what you want.
|
||||
@@ -217,22 +220,6 @@ class DjrillBackendTests(DjrillBackendMockAPITestCase):
|
||||
# Make sure the image attachments are not treated as embedded:
|
||||
self.assertFalse('images' in data['message'])
|
||||
|
||||
def test_extra_header_errors(self):
|
||||
email = mail.EmailMessage('Subject', 'Body', 'from@example.com',
|
||||
['to@example.com'],
|
||||
headers={'Non-X-Non-Reply-To-Header': 'not permitted'})
|
||||
with self.assertRaises(NotSupportedByMandrillError):
|
||||
email.send()
|
||||
|
||||
# Make sure fail_silently is respected
|
||||
email = mail.EmailMessage('Subject', 'Body', 'from@example.com',
|
||||
['to@example.com'],
|
||||
headers={'Non-X-Non-Reply-To-Header': 'not permitted'})
|
||||
sent = email.send(fail_silently=True)
|
||||
self.assertFalse(self.mock_post.called,
|
||||
msg="Mandrill API should not be called when send fails silently")
|
||||
self.assertEqual(sent, 0)
|
||||
|
||||
def test_alternative_errors(self):
|
||||
# Multiple alternatives not allowed
|
||||
email = mail.EmailMultiAlternatives('Subject', 'Body',
|
||||
|
||||
@@ -3,6 +3,9 @@ Release Notes
|
||||
|
||||
Version 0.9 (development):
|
||||
|
||||
* Allow all extra message headers in send.
|
||||
(Mandrill has relaxed previous API restrictions on headers.)
|
||||
|
||||
|
||||
Version 0.8:
|
||||
|
||||
|
||||
@@ -89,10 +89,11 @@ Some notes and limitations:
|
||||
Special handling for embedded images
|
||||
|
||||
**Headers**
|
||||
Djrill accepts additional headers, but only ``Reply-To`` and
|
||||
``X-*`` (since that is all that Mandrill accepts). Any other extra headers
|
||||
will raise :exc:`~djrill.NotSupportedByMandrillError` when you attempt to send the
|
||||
message.
|
||||
Djrill accepts additional headers and passes them along to Mandrill.
|
||||
|
||||
.. versionchanged:: 0.9
|
||||
In earlier versions, Djrill only allowed ``Reply-To`` and ``X-*`` headers,
|
||||
matching previous Mandrill API restrictions.
|
||||
|
||||
|
||||
.. _mandrill-send-support:
|
||||
|
||||
Reference in New Issue
Block a user