python Socketプログラミング(三)----STMP POP 3
1173 ワード
ドアを開ける例:
'''
Created on 2012-3-9
@author: Administrator
'''
#!/usr/bin/env python
from smtplib import SMTP
from poplib import POP3
from time import sleep
SMTPSVR='smtp.163.com'
POP3SVR='pop3.126.com'
origHdrs=['From:[email protected]',
'To:[email protected]',
'Subject:testMsg']
origBody=['xxx','yyy','zzz']
origMsg='\r
\r
'.join(['\r
'.join(origHdrs),'\r
'.join(origBody)])
print origMsg
sendSvr=SMTP(SMTPSVR)
sendSvr.login('XXXX', 'AAAA')
errs=sendSvr.sendmail('[email protected]', ('[email protected]',), origMsg)
sendSvr.quit()
assert len(errs) ==0,errs
print 'smtp over!'
recvSvr=POP3(POP3SVR)
recvSvr.user('YYYY')
recvSvr.pass_('BBBB')
rsp,meg,siz=recvSvr.retr(recvSvr.stat()[0])
sep=meg.index('')
recvBody=meg[sep+1:]
print recvBody
例は簡単smtp origMsgパッチワーク時のルールに注意し、pop 3注意
'''
Created on 2012-3-9
@author: Administrator
'''
#!/usr/bin/env python
from smtplib import SMTP
from poplib import POP3
from time import sleep
SMTPSVR='smtp.163.com'
POP3SVR='pop3.126.com'
origHdrs=['From:[email protected]',
'To:[email protected]',
'Subject:testMsg']
origBody=['xxx','yyy','zzz']
origMsg='\r
\r
'.join(['\r
'.join(origHdrs),'\r
'.join(origBody)])
print origMsg
sendSvr=SMTP(SMTPSVR)
sendSvr.login('XXXX', 'AAAA')
errs=sendSvr.sendmail('[email protected]', ('[email protected]',), origMsg)
sendSvr.quit()
assert len(errs) ==0,errs
print 'smtp over!'
recvSvr=POP3(POP3SVR)
recvSvr.user('YYYY')
recvSvr.pass_('BBBB')
rsp,meg,siz=recvSvr.retr(recvSvr.stat()[0])
sep=meg.index('')
recvBody=meg[sep+1:]
print recvBody
例は簡単smtp origMsgパッチワーク時のルールに注意し、pop 3注意
retr最近の1通を選択し、残りはxxxxx、yyyy、aaaaa、bbbbを自分のメールユーザー名とパスワードに変えればよい.