mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 03:41:05 -05:00
MailerSend: support extra headers
MailerSend added a `"headers"` API field (which is available to "Enterprise accounts only").
This commit is contained in:
@@ -145,23 +145,6 @@ class MailerSendBackendStandardEmailTests(MailerSendBackendMockAPITestCase):
|
||||
)
|
||||
|
||||
def test_custom_headers(self):
|
||||
email = mail.EmailMessage(
|
||||
"Subject",
|
||||
"Body goes here",
|
||||
"from@example.com",
|
||||
["to1@example.com"],
|
||||
headers={
|
||||
"Reply-To": "another@example.com",
|
||||
"In-Reply-To": "12345@example.com",
|
||||
"X-MyHeader": "my value",
|
||||
"Message-ID": "mycustommsgid@example.com",
|
||||
"Precedence": "Bulk",
|
||||
},
|
||||
)
|
||||
with self.assertRaisesMessage(AnymailUnsupportedFeature, "extra_headers"):
|
||||
email.send()
|
||||
|
||||
def test_supported_custom_headers(self):
|
||||
email = mail.EmailMessage(
|
||||
"Subject",
|
||||
"Body goes here",
|
||||
@@ -171,13 +154,20 @@ class MailerSendBackendStandardEmailTests(MailerSendBackendMockAPITestCase):
|
||||
"Reply-To": "another@example.com",
|
||||
"In-Reply-To": "12345@example.com",
|
||||
"Precedence": "Bulk",
|
||||
# Other custom headers only available to enterprise accounts:
|
||||
"X-Custom": "custom header",
|
||||
},
|
||||
)
|
||||
email.send()
|
||||
data = self.get_api_call_json()
|
||||
# Special handling headers:
|
||||
self.assertEqual(data["reply_to"], {"email": "another@example.com"})
|
||||
self.assertEqual(data["in_reply_to"], "12345@example.com")
|
||||
self.assertIs(data["precedence_bulk"], True)
|
||||
# Other headers:
|
||||
self.assertEqual(
|
||||
data["headers"], [{"name": "X-Custom", "value": "custom header"}]
|
||||
)
|
||||
|
||||
def test_html_message(self):
|
||||
text_content = "This is an important message."
|
||||
@@ -607,6 +597,7 @@ class MailerSendBackendAnymailFeatureTests(MailerSendBackendMockAPITestCase):
|
||||
self.assertNotIn("reply_to", data)
|
||||
self.assertNotIn("html", data)
|
||||
self.assertNotIn("attachments", data)
|
||||
self.assertNotIn("headers", data)
|
||||
self.assertNotIn("template_id", data)
|
||||
self.assertNotIn("tags", data)
|
||||
self.assertNotIn("variables", data)
|
||||
|
||||
@@ -81,8 +81,13 @@ class MailerSendBackendIntegrationTests(AnymailTestMixin, SimpleTestCase):
|
||||
bcc=["test+bcc1@anymail.dev", "Blind Copy 2 <test+bcc2@anymail.dev>"],
|
||||
# MailerSend only supports single reply_to:
|
||||
reply_to=["Reply <reply@example.com>"],
|
||||
# MailerSend supports very limited extra headers:
|
||||
headers={"Precedence": "bulk", "In-Reply-To": "earlier-id@anymail.dev"},
|
||||
headers={
|
||||
# Special handling for these headers (available to all accounts):
|
||||
"Precedence": "bulk",
|
||||
"In-Reply-To": "earlier-id@anymail.dev",
|
||||
# Only "enterprise accounts" can send other custom headers:
|
||||
"X-Custom": "anymail test",
|
||||
},
|
||||
send_at=send_at,
|
||||
tags=["tag 1", "tag 2"],
|
||||
track_clicks=False,
|
||||
|
||||
Reference in New Issue
Block a user