2011-10-28 87 views

回答

5

你可能要檢查出IMAPClient庫,擺脫了很多處理IMAP的坎坷的。

這是你將如何使用IMAPClient獲得與附件的電子郵件:

from imapclient import IMAPClient 

HOST = 'imap.gmail.com' 
USERNAME = '' 
PASSWORD = '' 
ssl = True 

server = IMAPClient(HOST, use_uid=True, ssl=ssl) 
server.login(USERNAME, PASSWORD) 

server.select_folder('INBOX') 
messages = server.search(['X-GM-RAW has:attachment']) 

print '%d messages with attachments' % (len(messages),) 
print 
print 'UIDs of messages with attachments:' 
print messages 

結果:

 
1 messages with attachments 

UIDs of messages with attachments: 
[85L]