客户端SMTP和POP3举例
#!/usr/bin/env pythonfrom smtplib import SMTPfrom poplib import POP3from time import sleepSMTPSVR = 'smtp.126.com'POP3SVR = 'pop.qq.com'origHdrs = ['From:RushengYang@126.com','To
·
</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
更多推荐
已为社区贡献2条内容
所有评论(0)