python-发送邮件

Posted on 2014-12-25 15:51  xiaohui.geng  阅读(171)  评论(0)    收藏  举报

来自:http://www.cnblogs.com/lonelycatcher/archive/2012/02/09/2343463.html#commentform

  • #!/usr/bin/env python3 
  • #coding: utf-8 
  • import smtplib 
  • from email.mime.text import MIMEText 
  • from email.header import Header 
  •  
  • sender = '***' 
  • receiver = '***' 
  • subject = 'python email test' 
  • smtpserver = 'smtp.163.com' 
  • username = '***' 
  • password = '***' 
  •  
  • msg = MIMEText('你好','text','utf-8')#中文需参数‘utf-8’,单字节字符不需要 
  • msg['Subject'] = Header(subject, 'utf-8'
  •  
  • smtp = smtplib.SMTP()
  • smtp.connect('smtp.163.com'
  • smtp.login(username, password) 
  • smtp.sendmail(sender, receiver, msg.as_string()) 
  • smtp.quit()

目前只是过这种。

//2014-12-30 add

使用MIMEImage可实现图片的发送,使外网用户也能看到图片

博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3