kidig / django-mailjet

A Django email backend for use with Mailjet (un-official project)
MIT License
16 stars 13 forks source link

Sending HTML mail as main content does not work #1

Open mlorant opened 8 years ago

mlorant commented 8 years ago

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 commented 8 years ago

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", "do-not-reply@domain.com", "recipient@domain.com"
 )
 mail.attach_alternative("HTML message", 'text/html')
 mail.send()

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