【问题标题】:HTML Email Rendered Incorrectly When Carriage Returns Are Not Used未使用回车时 HTML 电子邮件呈现不正确
【发布时间】:2013-03-12 02:02:06
【问题描述】:

以下 python 脚本会生成一个电子邮件文件,该文件可以通过管道传送到 sendmail。当我将它发送到我的 gmail 帐户时,第 25、50 和 51 行并不是我所期望的。所有其他行都按预期显示。

import sys
print "From:test@test.com"
print "To:you@you.com"
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 中尝试过,效果相同。不使用回车出现意外结果的原因是什么?

【问题讨论】:

    标签: python html email html-email


    【解决方案1】:

    不确定这是否是一个错字,但一方面你没有关闭你的行。你错过了一个:

    </tr>
    

    以及打开和关闭表格标签。

    【讨论】:

    • 谢谢@ptutt。我用行上的结束标签以及打开和关闭表格标签更新了脚本,但仍然遇到了问题。在这种情况下,第 26 行和第 46 行有意想不到的结果。第 22 行:test22 no carriage returns! !。线路:46:te! st46 no carriage returns
    • 我使用结束标签生成的新输出文件确实使用 HTML 验证器工具进行了验证。
    猜你喜欢
    • 2018-04-18
    • 2022-01-24
    • 2017-03-06
    • 2020-08-01
    • 2011-10-28
    • 1970-01-01
    • 2015-10-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多