def test_template_unsupported(self): """A lot of options are not compatible with SendBulkTemplatedEmail""" message = AnymailMessage(template_id="welcome_template", to=['*****@*****.**']) message.subject = "nope, can't change template subject" with self.assertRaisesMessage(AnymailUnsupportedFeature, "overriding template subject"): message.send() message.subject = None message.body = "nope, can't change text body" with self.assertRaisesMessage(AnymailUnsupportedFeature, "overriding template body content"): message.send() message.content_subtype = "html" with self.assertRaisesMessage(AnymailUnsupportedFeature, "overriding template body content"): message.send() message.body = None message.attach("attachment.txt", "this is an attachment", "text/plain") with self.assertRaisesMessage(AnymailUnsupportedFeature, "attachments with template"): message.send() message.attachments = [] message.extra_headers = {"X-Custom": "header"} with self.assertRaisesMessage(AnymailUnsupportedFeature, "extra_headers with template"): message.send() message.extra_headers = {} message.metadata = {"meta": "data"} with self.assertRaisesMessage(AnymailUnsupportedFeature, "metadata with template"): message.send() message.metadata = None message.tags = ["tag 1", "tag 2"] with self.assertRaisesMessage(AnymailUnsupportedFeature, "tags with template"): message.send() message.tags = None
def send_email(identifier, to, subject, template_data): logger.info("Sending receipt email id:%s to:%s subject:%s", identifier, to, subject) message = AnymailMessage() message.template_id = identifier message.to = [ to, ] message.subject = subject message.merge_global_data = template_data message.send()