我正在使用以下代码在 Outlook 中通过电子邮件发送文本文件“gerrit.txt”@ http://pastie.org/8289257的内容 ,但是当我查看源代码(@ http:// pastie.org/8289379)在Outlook中的电子邮件中,我在代码中看到了不必要的感叹号(!),这弄乱了输出,任何人都可以提供有关为什么会这样以及如何避免这种情况的输入吗?
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()