diff --git a/anymail/backends/base.py b/anymail/backends/base.py index c947276..af85db2 100644 --- a/anymail/backends/base.py +++ b/anymail/backends/base.py @@ -322,11 +322,16 @@ class BasePayload(object): def set_alternatives(self, alternatives): for content, mimetype in alternatives: - self.add_alternative(content, mimetype) + if mimetype == "text/html": + # This assumes that there's at most one html alternative, + # and so it should be the html body. (Most ESPs don't + # support multiple html alternative parts anyway.) + self.set_html_body(content) + else: + self.add_alternative(content, mimetype) def add_alternative(self, content, mimetype): - raise NotImplementedError("%s.%s must implement add_alternative or set_alternatives" % - (self.__class__.__module__, self.__class__.__name__)) + self.unsupported_feature("alternative part with type '%s'" % mimetype) def set_attachments(self, attachments): for attachment in attachments: diff --git a/anymail/backends/mandrill.py b/anymail/backends/mandrill.py index 9f540ff..55b8801 100644 --- a/anymail/backends/mandrill.py +++ b/anymail/backends/mandrill.py @@ -117,15 +117,10 @@ class MandrillPayload(RequestsPayload): self.data["message"]["text"] = body def set_html_body(self, body): - self.data["message"]["html"] = body - - def add_alternative(self, content, mimetype): - if mimetype != 'text/html': - self.unsupported_feature("alternative part with mimetype '%s'" % mimetype) - elif "html" in self.data["message"]: + if "html" in self.data["message"]: + # second html body could show up through multiple alternatives, or html body + alternative self.unsupported_feature("multiple html parts") - else: - self.set_html_body(content) + self.data["message"]["html"] = body def add_attachment(self, attachment): key = "images" if attachment.inline else "attachments"