Mailgun: Support stored templates

Add support for Mailgun's new template option

Fixes #155
This commit is contained in:
Ansel Santosa
2019-07-30 10:50:42 -07:00
committed by Mike Edmunds
parent df3d577b41
commit 73a73ea01f
3 changed files with 9 additions and 9 deletions

View File

@@ -253,8 +253,8 @@ class MailgunPayload(RequestsPayload):
def set_track_opens(self, track_opens):
self.data["o:tracking-opens"] = "yes" if track_opens else "no"
# template_id: Mailgun doesn't offer stored templates.
# (The message body and other fields *are* the template content.)
def set_template_id(self, template_id):
self.data["template"] = template_id
def set_merge_data(self, merge_data):
# Processed at serialization time (to allow merging global data)

View File

@@ -233,14 +233,10 @@ Limitations and quirks
.. _mailgun-templates:
Batch sending/merge and ESP templates
Batch sending/merge
-------------------------------------
Mailgun does not offer :ref:`ESP stored templates <esp-stored-templates>`,
so Anymail's :attr:`~anymail.message.AnymailMessage.template_id` message
attribute is not supported with the Mailgun backend.
Mailgun *does* support :ref:`batch sending <batch-send>` with per-recipient
Mailgun supports :ref:`batch sending <batch-send>` with per-recipient
merge data. You can refer to Mailgun "recipient variables" in your
message subject and body, and supply the values with Anymail's
normalized :attr:`~anymail.message.AnymailMessage.merge_data`

View File

@@ -448,7 +448,11 @@ class MailgunBackendAnymailFeatureTests(MailgunBackendMockAPITestCase):
self.assertEqual(data['o:tracking-opens'], 'no')
self.assertEqual(data['o:tracking-clicks'], 'yes')
# template_id: Mailgun doesn't support stored templates
def test_template_id(self):
self.message.template_id = "welcome_template"
self.message.send()
data = self.get_api_call_data()
self.assertEqual(data['template'], "welcome_template")
def test_merge_data(self):
self.message.to = ['alice@example.com', 'Bob <bob@example.com>']