bameda/djmail

Message.from_email_message stores HTML in field body_text

Closed this issue · 1 comments

Body is not always text/plain but sometimes text/html 746236d.
However this https://github.com/niwibe/djmail/blob/master/djmail/models.py#L67 always sets body_text to email.body even if this is text/html.

Indeed, there is something wrong here.

Relevant construction code:

        if body_txt and body_html:
            email = mail.EmailMultiAlternatives(**kwargs)
            email.body = body_txt
            email.attach_alternative(body_html, "text/html")

        elif not body_txt and body_html:
            email = mail.EmailMessage(**kwargs)
            email.content_subtype = "html"
            email.body = body_html

So the code for from_email_message() should check if content_subtype is text/html and if it is, use body_html instead of body_text.