#!/usr/bin/python
#coding=utf-8
#发送邮件 import smtplib
from smtplib import SMTP as smtp
import getpass mail_host="smtp.126.com"
mail_user="[email protected]"
mail_pass=getpass.getpass('password') sender="[email protected]"
receiver=['[email protected]'] message= '''From:[email protected]\r\nTo:[email protected]\r\nSubject:test msg\r\n\r\nPython test email\r\n'''
print message try:
smtpobj=smtp(mail_host)
smtpobj.login(mail_user,mail_pass)
smtpobj.sendmail(sender,receiver,message)
print "OK"
except smtplib.SMTPException,e:
print "Error:",e
smtpobj.quit()
 #!/usr/bin/python
#coding=utf-8
#接收邮件 import getpass
from poplib import POP3 p=POP3("pop.126.com")
p.user('[email protected]')
pwd=getpass.getpass("password")
p.pass_(pwd) msg_ct,mbox_siz=p.stat() #返回状态
rsp,msg,siz=p.retr(msg_ct) print rsp,siz for eachLine in msg:
print eachLine
05-11 22:41