SMTP and POP3 Example : SMTP : Network PYTHON TUTORIALS


PYTHON TUTORIALS » Network » SMTP »

 

SMTP and POP3 Example


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

SMTPSVR = 'smtp.python.is.cool'
POP3SVR = 'pop.python.is.cool'

origHdrs = ['From: from@python.com',
     'To: to@python.com',
     'Subject: test msg']
origBody = ['xxx', 'yyy', 'zzz']
origMsg = 'rnrn'.join(['rn'.join(origHdrs),'rn'.join(origBody)])

sendSvr = SMTP(SMTPSVR)
errs = sendSvr.sendmail('from@python.com',('to@python.com',), origMsg)
sendSvr.quit()
assert len(errs== 0, errs
sleep(10)

recvSvr = POP3(POP3SVR)
recvSvr.user('wesley')
recvSvr.pass_('youllNeverGuess')
rsp, msg, siz = recvSvr.retr(recvSvr.stat()[0])

sep = msg.index('')
recvBody = msg[sep+1:]
assert origBody == recvBody



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Network
» SMTP