2013-03-12 77 views
0

以下python脚本会生成一个可以通过管道发送到sendmail的电子邮件文件。当我把这个发送到我的Gmail账户时,第25,50和51行并不是我所期望的。所有其他行按预期显示。当电子邮件返回未使用时HTML电子邮件呈现错误

import sys 
print "From:[email protected]" 
print "To:[email protected]" 
print "Subject: test no carriage return" 
print "MIME-Version: 1.0" 
print "Content-Disposition: inline;" 
print "Content-Type: text/html" 
sys.stdout.write ("<html>") 
count = 1 
while (count < 55): 
# output without a carriage return 
sys.stdout.write("<tr><td>test" + str(count) + " no carriage returns!</td>") 
count = count + 1 
sys.stdout.write ("</html>") 

在电子邮件我希望这对线25,50,51:

test25 no carriage returns! 
test50 no carriage returns! 
test51 no carriage returns! 

代替,这是呈现:

test25 no carriage retur! ns! 
test50 no ca! rriage returns! 
test51 no carriage returns!  test52 no carriage returns! 

如果我改变输出使用print而不是stdout,那么电子邮件按预期显示。我也在MS Outlook中尝试过,效果相同。回车未使用时出现意外结果的原因是什么?

回答

0

不知道它是否是一个错字,但有一件事你不关闭你的行。你错过了:

</tr> 

以及打开和关闭表标记。

+0

谢谢@ptutt。我使用结束标记更新了脚本以及打开和关闭表标记并仍然遇到问题。在这种情况下,第26行和第46行有意想不到的结果。第22行:'test22没有回车! '''。 Line:46:'te! st46 no carriage returns' – Bill 2013-03-12 03:44:49

+0

我使用结束标签生成的新输出文件使用HTML验证器工具进行验证。 – Bill 2013-03-12 03:54:37