emailtext.txt
我在文本文件@ http://pastie.org/8276028中有一个 HTML 代码,目前我正在使用以下代码以 HTML 格式发送电子邮件(通过 Outlook),但有时格式似乎混乱......有人可以提供有关如何以可靠方式发送此电子邮件的意见?
from email.mime.text import MIMEText
from subprocess import check_call,Popen,PIPE
def email (body,subject,to=None):
msg = MIMEText("%s" % body)
msg['Content-Type'] = "text/html; charset=UTF8"
msg["From"] = "userid@qualcomm.com"
if to!=None:
to=to.strip()
msg["To"] = to
else:
msg["To"] = "userid2@company.com"
msg["Subject"] = '%s' % subject
p = Popen(["/usr/sbin/sendmail", "-t", "-f" + msg["From"]], stdin=PIPE)
p.communicate(msg.as_string())
print "Done"
def main ():
with open('emailtext.txt', 'r') as f:
body = f.read()
Subject ="test email"
email(body, Subject, "userid3@company.com")
if __name__ == '__main__':
main()