Chinaunix首页 | 论坛 | 博客
  • 博客访问: 938109
  • 博文数量: 403
  • 博客积分: 27
  • 博客等级: 民兵
  • 技术积分: 165
  • 用 户 组: 普通用户
  • 注册时间: 2011-12-25 22:20
文章分类

全部博文(403)

文章存档

2016年(3)

2015年(16)

2014年(163)

2013年(222)

分类: Python/Ruby

2013-05-30 15:03:30

原文地址:Python 发送邮件 smtplib 作者:huaius

可以利用smtplib模块来实现发送邮件的功能,一个比较简单的实例代码如下:


  1. # Import smtplib for the actual sending function
  2. import smtplib

  3. # Import the email modules we'll need
  4. from email.mime.text import MIMEText

  5. # Open a plain text file for reading. For this example, assume that
  6. # the text file contains only ASCII characters.
  7. # Create a text/plain message
  8. msg = MIMEText("some content")
  9. me = you = 'somebody@somewhere.com'

  10. # me == the sender's email address
  11. # you == the recipient's email address
  12. msg['Subject'] = 'The contents of somebody'
  13. msg['From'] = me
  14. msg['To'] = you

  15. # Send the message via our own SMTP server, but don't include the
  16. # envelope header.
  17. s = smtplib.SMTP('localhost')
  18. s.sendmail(me, [you], msg.as_string())
  19. s.quit()

更多更强大详细的功能可以参考 
阅读(996) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~