0👍
Message is plain text, while html_message is a message formatted using HTML. If you set both, probably your email client is displaying the HTML version.
3👍
The problem is that some (old or specifically configured) email clients won’t display HTML messages, therefore you need to make sure all your users can read your emails properly. If you decide to send just text, then users capable of getting HTML messages won’t benefit from it.
This is the strategy I follow:
I use django.template.loader.render_to_string
to render a template with a given context. The value this function returns is a string with a message in HTML.
html_text = render_to_string(template, context)
Then I create a plain text message based on the HTML message (for instance, by using a package named html2text
):
plain_text = html2text(html_text)
And finally I send the email with django.core.mail.send_mail
, passing html_text
and plain_text
as parameters.
- [Django]-Django 1.11 – static file not found
- [Django]-How to get Django South to migrate a field with changed max_length?