def SaveAttach():# login the pop3 server ,retrive the new mails ,and download the attachments
dstdir =dirname+str(time.ctime(time.time()))+'.zip'
print 'starts'
pp = poplib.POP3_SSL(mail_host,mail_port)
print 'connect successful'
pp.set_debuglevel(1)
pp.user(mail_user)
pp.pass_(mail_pass)
##list total count
num = len(pp.list()[1])
print 'num of messages', num
for i in range(1,num):
#m = M.retr(i+1)
m = pp.retr(i)
buf = cStringIO.StringIO()
buf.seek(0)
msg = email.message_from_file(buf)
for par in msg.walk():
#if not par.is_multipart():
name = par.get_filename()
if name:
print 'name',name
data = par.get_payload(decode=True)
python 利用pop3接收邮件并保存附件
最新推荐文章于 2024-01-30 10:39:07 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)