Check unread count of Gmail messages with Python

Steven Hepting picture Steven Hepting · Jun 5, 2009 · Viewed 28.1k times · Source

How can I check the number of unread Gmail message in my inbox with a short Python script? Bonus points for retrieving the password from a file.

Answer

Avadhesh picture Avadhesh · Oct 21, 2010
import imaplib
obj = imaplib.IMAP4_SSL('imap.gmail.com','993')
obj.login('username','password')
obj.select()
obj.search(None,'UnSeen')