Thomas_young2015 2017年07月26日
python发送html邮件缺少CSS样式



代码:
def send_mail_test(subject, content):
# 句柄
# msg = MIMEMultipart('related')
msg = MIMEText(content, 'html', 'base64')
msg['From'] = Header(u'<%s>' % sender, 'utf-8')
msg['To'] = Header(';'.join(receivers), 'utf-8')
msg['Subject'] = Header(subject, 'utf-8')

# 发送邮件
smtp = smtplib.SMTP()
try:
smtp.connect(mail_host, 25) # 25为SMTP端口号,465或者994为SSL协议端口
smtp.login(mail_user, mail_password)
smtp.sendmail(sender, receivers, msg.as_string())
print "发送邮件成功"
except smtplib.SMTPException:
print "Error, 发送邮件失败"
traceback.print_exc()
finally:
smtp.quit()


if __name__ == "__main__":
subject = u'【请阅】测试报告'
# content = u'含测试报告邮件测试'
# attach = scan_dir(SJ_RESULT, 'html')
# send_mail(subject, content, attach=attach)
file_html = scan_dir(SJ_RESULT, 'html')
with open(file_html, 'rb') as fp:
content = fp.read()

send_mail_test(subject, content)
...全文
253 点赞 收藏 2
写回复
2 条回复

还没有回复,快来抢沙发~

发动态
发帖子
脚本语言(Perl/Python)
创建于2007-08-27

1.5w+

社区成员

3.3w+

社区内容

其他开发语言 脚本语言(Perl ,Python)
社区公告
暂无公告