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('???@163.com','your password')
13         msg = 'To:??@qq.com\r\nFrom:??@163.com\r\nSubject:this is from cnblogs\r\n'
14         handle.sendmail('from mail@163.com',' 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,这不是昨天说的实验,只是昨天下午写的一个小程序。找时间看一下如何把我未读的邮件读出来,然后选择某一个进行查看。

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

posted @ 2012-12-29 09:25  Alexander.liu  阅读(1110)  评论(0编辑  收藏  举报