Skip to main content
 首页 » 编程设计

Python smtplib 破坏 html 电子邮件

2024年09月03日41wuhuacong

我的应用程序生成带有用于报告的表格的 html 电子邮件。

s = smtplib.SMTP(self.server)     
s.sendmail(self.addrFrom(), self.addrTo(), message.getvalue()) 

当我在发送之前检查 message.getvalue() 时,html 是有效的。但是,当我在将源发送到 Outlook 时检查源时,它显示为:

<TD>04/07/2011</TD><! 
 TD>30/04/2011</TD> 

代替:

<TD>04/07/2011</TD><TD>30/04/2011</TD> 

有人对正在发生的事情有任何想法吗?

请您参考如下方法:

这不是 Outlook(或与此相关的任何客户端)问题,而是符合 RFC 的服务器。

您必须调整自己的例程或导入 textwrap。

有关详细信息,请参阅 RFC 5321:

4.5.3.1.6. Text Line

The maximum total length of a text line including the is 1000 octets (not counting the leading dot duplicated for transparency). This number may be increased by the use of SMTP Service Extensions.

RFC 2821 表示相同。