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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值