使用smtplib 发送html文件,导入方式
#!/usr/bin/python #coding:utf-8 import smtplib from datetime import datetime, timedelta import time from email.MIMEText import MIMEText from email.MIMEText import MIMEText from email.MIMEMultipart import MIMEMultipart def get_html_msg(): html = open('/root/test.html','rb').read() return html def send_mail(html_msg): msg = MIMEMultipart() to_list = ["zhangwei@ulpay.com","zhangdl@ulpay.com","shiwm@ulpay.com"] content = MIMEText(html, _subtype='html', _charset='gb2312') msg.attach(content) msg['To'] = ";".join(to_list) #msg['To'] = to_list msg['From'] = "monitor@ulpay.com" msg['Subject'] = "test_adv" s = smtplib.SMTP('mail.ulpay.com') s.login('shiwm@ulpay.com','1234567890') s.set_debuglevel(0) s.sendmail(msg['From'], to_list, msg.as_string()) s.quit() print "ok" if __name__ == "__main__": html = get_html_msg() send_mail(html)
No Leanote account ? Sign up now.