我在文本文件“gerrit.txt”中有 HTML 代码 @ http://pastie.org/8289257 ,它将创建一个包含一些内容的表格,我将文本文件转换为 .htm 文件并打开它,输出看起来很完美很好,这告诉我 HTML 代码很好,但是当我使用下面的代码发送电子邮件(使用 Outlook)时,表格有时会搞砸。我需要关于我可以通过哪些其他方式发送电子邮件的想法?我尝试了 SMTP,如下所示,它似乎不起作用......
from email.mime.text import MIMEText
from smtplib import SMTP
def email (body,subject):
msg = MIMEText("%s" % body)
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()