2013-03-12 76 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