2010-06-09 504 views

回答

1

用於找到未讀消息的替代的Gmail特定溶液:

Gmail offers atom feeds for messages。例如:

https://mail.google.com/mail/feed/atom/(收件箱中的未讀郵件) http://mail.google.com/mail/feed/atom/labelname/(在標籤的未讀郵件) http://mail.google.com/mail/feed/atom/unread/(所有未讀郵件)

所以,你可以使用優秀的feedparser庫搶進給和計數的條目。

現在我正在看它,但看來未讀消息只會返回多達20個條目,所以這可能會有點受限。

4

看看python標準庫的POP3IMAP包。

+0

+1。打敗我吧。 – 2010-06-09 22:32:37

6

ü可以試試這個

import imaplib 
obj = imaplib.IMAP4_SSL('imap.gmail.com', 993) 
obj.login('username', 'password') 
obj.select('Inbox')  <-- it will return total number of mail in Inbox i.e 
('OK', ['50']) 
obj.search(None,'UnSeen') <-- it will return the list of uids for Unseen mails 
3

大廈Avadhesh的回答是:

#! /usr/bin/env python3.4 

import getpass 
import imaplib 

mail = imaplib.IMAP4_SSL('imap.server.com') 
mypassword = getpass.getpass("Password: ") 
address = '[email protected]' 
mail.login(address, mypassword) 
mail.select("inbox") 
print("Checking for new e-mails for ",address,".", sep='') 
typ, messageIDs = mail.search(None, "UNSEEN") 
messageIDsString = str(messageIDs[0], encoding='utf8') 
listOfSplitStrings = messageIDsString.split(" ") 
if len(listOfSplitStrings) == 0: 
    print("You have no new e-mails.") 
elif len(listOfSplitStrings) == 1: 
    print("You have",len(listOfSplitStrings),"new e-mail.") 
else: 
    print("You have",len(listOfSplitStrings),"new e-mails.") 
+0

嗨,你的回答真的幫了我很多。即時通訊新手上imaplib和即時通訊試圖獲得20最新的電子郵件在我們的IMAP服務器。你能幫我解釋我會怎麼做嗎? – hocuspocus31 2016-08-15 23:38:42

+0

看看這篇文章:http://stackoverflow.com/a/5641178/286807 – 2016-11-06 17:56:39

相關問題