我正在使用django send_mail这样的:
from django.core.mail import send_mail
send_mail('Test', 'asdfasdfasdf\nasdfasfasdfasdf\nasdfasdfasdf', '[email protected]', ['[email protected]'], fail_silently=False)
Gmail接收到此信息。
Content-type: multipart/alternative; boundary="----------=_1382512224-21042-56"
------------=_1382512224-21042-56
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
asdfasdfasdf
asdfasfasdfasdf
asdfasdfasdf
------------=_1382512224-21042-56
Content-Type: text/html; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
<html><body>
<p>asdfasdfasdf asdfasfasdfasdf asdfasdfasdf</p>
</body></html>
并将我的换行符显示为一整段。为什么?我想要三行文字,而不是一行。
最佳答案
尝试以HTML而不是纯文本格式发送电子邮件。使用EmailMessage()。
from django.core.mail import EmailMessage
msg = EmailMessage(
'Test',
'asdfasdfasdf<br>asdfasfasdfasdf<br>asdfasdfasdf',
'[email protected]',
['[email protected]', ]
)
msg.content_subtype = "html"
msg.send()
关于python - Python Django send_mail换行符?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19535369/