Skip to content

Instantly share code, notes, and snippets.

@tborychowski
Forked from vadviktor/gmail.py
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tborychowski/24dad7f8605ecee71dff to your computer and use it in GitHub Desktop.
Save tborychowski/24dad7f8605ecee71dff to your computer and use it in GitHub Desktop.
Gmail imap checker
#!/usr/bin/env python
def gmail_checker(username,password):
import imaplib,re
i=imaplib.IMAP4_SSL('imap.gmail.com')
try:
i.login(username,password)
x,y=i.status('INBOX','(MESSAGES UNSEEN)')
messages=int(re.search('MESSAGES\s+(\d+)',y[0]).group(1))
unseen=int(re.search('UNSEEN\s+(\d+)',y[0]).group(1))
return (messages,unseen)
except:
return False,0
messages,unseen = gmail_checker('username@gmail.com','password')
print "%i messages, %i unseen" % (messages,unseen)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment