Python发送html邮件

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 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/lexus/archive/2013/01/04/2843570.html

表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页