When im trying to send a mail with django send mail only the html message is coming and not the normal message i want to know the difference between both. Is there any best way to send mails through template or html files because i want a comming mailing system in my app.
Note:- the difference is of more important.
THIS IS WHAT I DID
msg_html = (' HELLLOOOOO') msg_plain = 'Normalallalaa
send_mail("titleeeee", msg_plain,"sender@test",["reciever@tese",],html_message=msg_html)
My mail contained only Hello in bold
Where did my message go.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With