在此输入代码...import imaplib
import email
import os
imaplib.IMAP4.debug = imaplib.IMAP4_SSL.debug = 1
Pwd = 'xxxxxx'
# Login mail
username, passwd = (Mail, Pwd)
con = imaplib.IMAP4_SSL(Host)
con.login(username, passwd)
con.select()
# Get all unseen mail
typ, data = con.search(None, '(UNSEEN)')
for num in data[0].split():
# retrieve the entire message
typ, data = con.fetch(num, '(RFC822)')
text = data[0][1]
msg = email.message_from_string(text)
for part in msg.walk():
# multipart
if part.get_content_maintype() == 'multipart':
continue
# No attached
if part.get('Content-Disposition') is None:
continue
# Get attached file name
filename = part.get_filename()
data = part.get_payload(decode=True)
if not data:
continue
# Download attached.
f = open('C:\\' + filename, 'w')
print 'C:\\', filename
f.write(data)
f.close()
con.close()
con.logout()