开发者

How do I send this email in Python, opening files and stuff?

开发者 https://www.devze.com 2022-12-31 21:23 出处:网络
msg = EmailMessage(subject, body, from_email, [to_email]) msg.content_subtype = \"html\" msg.send() This is how I send an email in Django.
msg = EmailMessage(subject, body, from_email, [to_email])
msg.content_subtype = "html"
msg.send()

This is how I send an email in Django.

But what开发者_如何学Python if I want to open a text file and take into account all its line breaks and tabs. I want to take the body of the text file (with line breaks \n) and email it as text of the "body".


If it's a text file, just send it as text. If you send it as "HTML", the whitespace won't be significant.


In Django itself, it uses render_to_string("", {}) from django.template.loader. The advantage of it is that you can use contexts.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号