电子邮件客户端程序SMTP和POP3代码

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

SMTPSVR = 'smtp.163.com'
POP3SVR = 'pop.163.com'

SENDER = RECVER = "lyb*****@163.com"
USER = "<span style="font-family: Arial, Helvetica, sans-serif;">lyb*****</span>" 
PAWD = "password"

origHdrs = ["From: %s" % SENDER, "To: %s" % RECVER, "Subject: from xingjianwen's letter"]
origBody = ["i love you", "saobinbin", "forever"]
origMsg = "\r\n\r\n".join(["\r\n".join(origHdrs), "\r\n".join(origBody)])

sendSvr = SMTP(SMTPSVR)
sendSvr.login(USER, PAWD) 
errs = sendSvr.sendmail(SENDER, (RECVER,), origMsg)
sendSvr.quit()
assert len(errs) == 0, errs
sleep(10) # wait for mail to be delivered

recvSvr = POP3(POP3SVR)
recvSvr.user(USER)
recvSvr.pass_(PAWD)
print recvSvr.stat()
rsp, msg, siz = recvSvr.retr(recvSvr.stat()[0])
sep = msg.index("") # empty-string
recvBody = msg[sep+1:]
assert origBody == recvBody # assert identical

print "done"

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页