python 使用poplib库pop3协议收邮件代码,pythonpoplib,# -*- coding
文章由Byrx.net分享于2019-03-23 11:03:55
python 使用poplib库pop3协议收邮件代码,pythonpoplib,# -*- coding
# -*- coding=GBK -*-import stringimport poplibimport StringIO, rfc822servername = "pop3.126.com"username = "yourname"passwd = "yourpass"#连接 登录 服务器pop = poplib.POP3(servername)pop.set_debuglevel(1) #会打印出debug信息pop.user(username)pop.pass_(passwd)#列出邮件信息num,total_size = pop.stat()#取得最新的邮件hdr,text,octet=pop.retr(num)#对邮件进行操作text = string.join(text, "\n")file = StringIO.StringIO(text)message = rfc822.Message(file)for k, v in message.items(): print k, "=", vprint message.fp.read()
评论关闭