我一直在与一个由 EmailMessage 类产生的神秘错误作斗争,其中我发送给自己的最后一封电子邮件以“!”插入整个正文。目前,我正在使用以下代码发送电子邮件:
html_content = render_to_string('layouts/option1.html', request.POST)
subject = "just a test email"
from_email = request.user.email
recipient = [from_email, ]
msg = EmailMessage(subject, html_content, from_email, to=recipient, headers={
'Content-Type': 'text/html; charset=ISO-8859-1',
'MIME-Version': '1.0'
})
msg.content_subtype = "html"
try:
msg.send()
response['success'] = True
response['html_content'] = html_content
except:
pass
我发现了一个类似的线程(但对于 php),它讨论了一些非常相似的东西。显然这与消息长度有关。事实上,我正在发送一封相当长的 html 电子邮件,但我无法实现模仿他们在我的链接中提出的解决方案的 pythonic 版本。
任何有关如何防止“!”出现的帮助或建议将不胜感激!!!
谢谢你,飞