我在Element上使用elementtree.ElementTree.dump生成html文件。这些文件在所有浏览器中看起来都很好,文件中的底层代码看起来很好(没有未闭合的括号或任何东西)。
当我通过smtplib向Outlook 2010发送电子邮件时,我发现了奇怪的格式问题。这些问题将是100%可重复的,因此问题是合乎逻辑的。这是一个例子:
<table b="" order="1">
这是我自己发送的HTML电子邮件的源代码。它被正确地写为:
<table border="1">
在原始源代码中。
如果在Outlook中我使用原始HTML作为源编写HTML电子邮件,则它会正确格式化。 (新的电子邮件附加html文件 - &gt;作为文本插入)
问题是Outlook还是Python?我用来读取html文件和发送的功能如下。
def email_Report(mailOptions):
reportName = time.strftime("%Y%m%d.%H%M") + ".html"
ElementTree(mailOptions['report']).write("/home/%s/%s" %(mailOptions['username'],reportName))
#Set sender and receiver to the user building the report.
mailaddr = '%s@acme.com' %(mailOptions['username'])
#Access the report file. Added binary in case we ever use code on Windows
filename = "/home/%s/%s" % (mailOptions['username'], reportName)
open_file = open(filename, 'rb')
emsg = MIMEText(open_file.read(), 'html')
open_file.close()
emsg['Subject'] = "Report for %s generated by %s %s" % (mailOptions['zone'], mailOptions['username'], time.strftime("%d%m%Y-%H%M"))
emsg['To'] = mailaddr
emsg['From'] = mailaddr
#Hostname can be a parameter to SMTP method if localhost isn't listening
sc = smtplib.SMTP()
sc.connect()
sc.sendmail(mailaddr, mailaddr, emsg.as_string())
sc.close()
return
HTML非常简单。没有CSS,没有标题或头部标签等。只是html-&gt; body-&gt; table-&gt; tr-&gt; th-&gt;(newrow) - &gt; td-&gt; td等我可以忽略像编码/逃避?我必须使用mime multipart吗?我使用的是Python 2.4.3,不能使用任何没有库存的模块。
答案 0 :(得分:1)
您确定没有按照规定运行邮件服务器的990字符限制 workaround for the 990 character limitation for email mailservers