NashZhou

广告算法工程师,目前致力于关键词广告的效果自动优化

Python发送html邮件

1 if __name__ == '__main__':    
2      ToUser='zhoujiebing@maimiaotech.com'
3      filestr = 'html'          
4      html =  file(filestr).read()    
5      sendEmail(ToUser, (filestr, html), u'主题')
 1  import sys 
 2  import smtplib
 3  from email.mime.text import MIMEText
 4  from email.mime.multipart import MIMEMultipart
 5  
 6  def sendEmail(msgTo, content, type):
 7      (attachment,html) = content
 8      msg = MIMEMultipart()
 9      msg['Subject'] = type
10      msg['From'] = 'zhoujiebing@maimiaotech.com'
11      msg['To'] = msgTo
12      html_att = MIMEText(html, 'html', 'utf-8')
13      att = MIMEText(attachment, 'plain', 'utf-8')
14      msg.attach(html_att)
15      msg.attach(att)
16      try:
17          smtp = smtplib.SMTP()
18          smtp.connect('smtp.**.163.com', 25)
19          smtp.login(msg['From'], '自己邮箱密码')
20          smtp.sendmail(msg['From'], msg['To'].split(','), msg.as_string())
21      except Exception,e:
22          print e

posted on 2012-08-24 15:58  NashZhou  阅读(4614)  评论(0编辑  收藏  举报

导航