`
wyunfuby
  • 浏览: 5199 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

Python 发送邮件 smtplib

阅读更多

可以利用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. = smtplib.SMTP('localhost')
  18. s.sendmail(me, [you], msg.as_string())
  19. s.quit()
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics