1 #!/usr/bin/python 2 #coding=utf-8 3 #发送邮件 4 5 import smtplib 6 from smtplib import SMTP as smtp 7 import getpass 8 9 mail_host="smtp.126.com" 10 mail_user="lijunyong3@126.com" 11 mail_pass=getpass.getpass('password') 12 13 sender="lijunyong3@126.com" 14 receiver=['lijunyong3@126.com'] 15 16 message= '''From:lijunyong3@126.com To:lijunyong3@126.com Subject:test msg Python test email ''' 17 print message 18 19 try: 20 smtpobj=smtp(mail_host) 21 smtpobj.login(mail_user,mail_pass) 22 smtpobj.sendmail(sender,receiver,message) 23 print "OK" 24 except smtplib.SMTPException,e: 25 print "Error:",e 26 smtpobj.quit()
1 #!/usr/bin/python 2 #coding=utf-8 3 #接收邮件 4 5 import getpass 6 from poplib import POP3 7 8 p=POP3("pop.126.com") 9 p.user('lijunyong3@126.com') 10 pwd=getpass.getpass("password") 11 p.pass_(pwd) 12 13 msg_ct,mbox_siz=p.stat() #返回状态 14 rsp,msg,siz=p.retr(msg_ct) 15 16 print rsp,siz 17 18 for eachLine in msg: 19 print eachLine