</pre><pre name="code" class="html">#!/usr/bin/env python

from smtplib import SMTP
from poplib import POP3
from time import sleep

SMTPSVR = 'smtp.126.com'
POP3SVR = 'pop.qq.com'

origHdrs = ['From:RushengYang@126.com',
            'To:752262774@qq.com ',
            'Subject:test msg']
origBody = ['xxx','yyy','zzz']
origMsg = '\r\n\r\n'.join(['\r\n'.join(origHdrs),
                           '\r\n'.join(origBody)])

sendSvr = SMTP(SMTPSVR)
sendSvr.set_debuglevel(1)
sendSvr.login("RushengYang","*********")
errs = sendSvr.sendmail('RushengYang@126.com',
    ('752262774@qq.com',) ,origMsg)
sendSvr.quit()
assert len(errs) == 0,errs
sleep(10)

recvSvr = POP3(POP3SVR)
recvSvr.user('752262774')
recvSvr.pass_('********')
rsp,msg,siz = recvSvr.retr(recvSvr.stat()[0])
sep = msg.index('')
recvBody = msg[sep+1:]
print recvBody

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐