不必要的感叹号(!)在HTML代码中 [英] unnecessary exclamation marks(!)'s in HTML code

查看:601
本文介绍了不必要的感叹号(!)在HTML代码中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过电子邮件发送文本文件gerrit.txt的内容@ http://pastie.org/8289257在外观中使用以下代码,
,但是在发送电子邮件时,我查看源代码(@ http ://pastie.org/8289379 )在Outlook中的电子邮件,我看到不必要的
感叹号(!)在代码中混乱输出,任何人都可以提供输入为什么这样做,如何避免这种情况?

I am emailing the content of a text file "gerrit.txt" @ http://pastie.org/8289257 in outlook using the below code, however after the email is sent when I look at the source code( @http://pastie.org/8289379) of the email in outlook ,i see unnecessary exclamation markds(!)'s in the code which is messing up the output, can anyone provide inputs on why is it so and how to avoid this ?

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('userid@company.com', ['userid2@company.com'],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


请注意,邮件服务器对每行都有990个字符的限制
包含在电子邮件中。如果发送电子邮件消息,
包含长度超过990个字符的行,那么这些行将为
,以额外的行结尾字符细分,这可能导致电子邮件中的
损坏,特别是对于HTML内容。要
防止发生这种情况,请在电子邮件中的
适当位置添加自己的行结束字符,以确保没有行
的长度超过990个字符。

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 方法。

I think you must split your html to some lines. You can use textwrap.wrap method.

这篇关于不必要的感叹号(!)在HTML代码中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆