开发者

Python smtplib corrupting html emails

My application generates html emails with tables used for reporting.

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

When I check message.getvalue() before it gets sent, the html is valid. However, when I check the source when it gets sent to outlook it comes up as:

<TD>04/0开发者_JAVA技巧7/2011</TD><!
 TD>30/04/2011</TD>

instead of:

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

anyone have any ideas on what's happening?


This is not an Outlook (or any client for that matter) issue, rather servers conforming to RFCs.

You'll have to right your own routine or import textwrap.

Refer to RFC 5321 for more detail:

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 indicates the same.


What are you sending for a content-type header? Remember the headers have to precede the message body in the 3rd arg to sendmail(from, to, mail), each header should end with \r\n, and there should be a final \r\n after the final header, meaning \r\n\r\n separating the last header from the message body.

Or actually, you should probably use \n rather than \r\n because of all the noncompliant MTAs out there.


You should be using the email package to generate a proper, MIME encoded email body.

you might also want to try out my ezmail.py module, that does most of that for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜