2010-06-09 191 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

相关问题