diff --git a/anymail/backends/mailgun.py b/anymail/backends/mailgun.py index 2af8cc5e..cd33acd2 100644 --- a/anymail/backends/mailgun.py +++ b/anymail/backends/mailgun.py @@ -253,8 +253,8 @@ def set_track_clicks(self, track_clicks): 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) diff --git a/docs/esps/mailgun.rst b/docs/esps/mailgun.rst index 5b580742..71a20154 100644 --- a/docs/esps/mailgun.rst +++ b/docs/esps/mailgun.rst @@ -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 `, -so Anymail's :attr:`~anymail.message.AnymailMessage.template_id` message -attribute is not supported with the Mailgun backend. - -Mailgun *does* support :ref:`batch sending ` with per-recipient +Mailgun supports :ref:`batch sending ` 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` diff --git a/tests/test_mailgun_backend.py b/tests/test_mailgun_backend.py index d42dda4d..f213ec96 100644 --- a/tests/test_mailgun_backend.py +++ b/tests/test_mailgun_backend.py @@ -448,7 +448,11 @@ def test_tracking(self): 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 ']