+-

我使用下面的代码通过电子邮件发送文本文件“gerrit.txt”@ http://pastie.org/8289257的内容,
然而,当我查看Outlook中电子邮件的源代码(@ http://pastie.org/8289379)发送电子邮件后,我认为没有必要
代码中的感叹号(!)在搞乱输出,任何人都可以提供输入,为什么会这样,以及如何避免这种情况?
然而,当我查看Outlook中电子邮件的源代码(@ http://pastie.org/8289379)发送电子邮件后,我认为没有必要
代码中的感叹号(!)在搞乱输出,任何人都可以提供输入,为什么会这样,以及如何避免这种情况?
from email.mime.text import MIMEText
from smtplib import SMTP
def email (body,subject):
msg = MIMEText("%s" % body, 'html')
msg['Content-Type'] = "text/html; charset=UTF8"
msg['Subject'] = subject
s = SMTP('localhost',25)
s.sendmail('[email protected]', ['[email protected]'],msg=msg.as_string())
def main ():
# open gerrit.txt and read the content into body
with open('gerrit.txt', 'r') as f:
body = f.read()
subject = "test email"
email(body,subject)
print "Done"
if __name__ == '__main__':
main()
最佳答案
这里有一些信息: http://bugs.python.org/issue6327
Note that mailservers have a 990-character limit on each line
contained within an email message. If an email message is sent that
contains lines longer than 990-characters, those lines will be
subdivided by additional line ending characters, which can cause
corruption in the email message, particularly for HTML content. To
prevent this from occurring, add your own line-ending characters at
appropriate locations within the email message to ensure that no lines
are longer than 990 characters.
我认为你必须将你的HTML分成几行.您可以使用textwrap.wrap方法.
点击查看更多相关文章
转载注明原文:python – HTML代码中不必要的感叹号(!) - 乐贴网