python2.7发邮件小程序

python2.7发邮件小程序 mail.py
 1 #encoding=utf-8

 2 

 3 import sys

 4 import time

 5 import email

 6 import smtplib

 7 import poplib

 8 

 9 def send_mail():

10     try:

11         handle = smtplib.SMTP('smtp.163.com',25)

12         handle.login('[email protected]','your password')

13         msg = 'To:[email protected]\r\nFrom:[email protected]\r\nSubject:this is from cnblogs\r\n'

14         handle.sendmail('from [email protected]',' To mail @qq.com',msg)

15         handle.close()

16         return 1

17     except smtplib.SMTPConnectError, e:

18         print "error", e

19         return 0

20 def check_mail():

21     try:

22         p = poplib.POP3('pop.163.com')

23         p.user('???@163.com')

24         p.pass_('your password')

25         ret = p.stat()

26         print ret

27         msglist = p.list()

28         print msglist[0]

29         for msg in msglist[1]:

30             print msg

31     except poplib.error_proto, e:

32         print 'login failed',e

33         sys.exit(1)

34 

35 if __name__ == "__main__":

36     send_mail()

37     accept_mail()

运行环境2.7.2,这不是昨天说的实验,只是昨天下午写的一个小程序。找时间看一下如何把我未读的邮件读出来,然后选择某一个进行查看。

昨天说的实验我已经基本确定要弄的东西了。

你可能感兴趣的:(python2.7)