浙江省高等学校教师教育理论培训

微信搜索“教师资格证岗前培训”小程序

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Python发送html邮件 - 2010Freeze - 博客园

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 2013-01-04 01:25  lexus  阅读(314)  评论(0编辑  收藏  举报