django-mailjet icon indicating copy to clipboard operation
django-mailjet copied to clipboard

Sending HTML mail as main content does not work

Open mlorant opened this issue 8 years ago • 1 comments

Using MailjetBackend with the following Django code:

    email = EmailMessage(subject, message, from_email, recipients)
    email.content_subtype = 'html'
    email.send()

... where message contains some HTML tags is sending to the recipient(s) a plain text mail, where the HTML is not interpreted.

Attaching two alternatives (plain & html) works though, but since the code above is documented as official part of the Django API, I think it should be handled.

EDIT: I should mention this method worked with another competitor backend before :confused:

mlorant avatar May 11 '16 15:05 mlorant

For information (and those who might be blocked by this), it is possible to workaround this problem by using the following method:

 from django.core.mail import EmailMultiAlternatives

 mail = EmailMultiAlternatives(
     "Subject", "Plain text message", "[email protected]", "[email protected]"
 )
 mail.attach_alternative("HTML message", 'text/html')
 mail.send()

Thus, mail provider seems to prefer displaying the HTML version instead of the plain one.

mlorant avatar Aug 24 '16 09:08 mlorant