Prior to Django 1.7 (currently in dev), we don’t have any option to pass html version of an email to “send_mail()” from django.core.mail module. Even in the newer version, you can pass html template as an alternative but you have to pass a plain text version as well. What if you want to send html version, only? This is what I did –
from django.core.mail import EmailMessage
def send_email(to_list, subject, message, sender="Aircourts <[email protected]>"):
msg = EmailMessage(subject, message, sender, to_list)
msg.content_subtype = "html" # Main content is now text/html
Now you would pass html as the message parameter. I use django templates with “render_to_string()” function from django.template.loader module.
Do you know any other, perhaps smarter way to accomplish this? Please share in the comments! 🙂