Skip to content

Instantly share code, notes, and snippets.

@joshbirk
Created January 17, 2012 16:23
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 joshbirk/1627326 to your computer and use it in GitHub Desktop.
Save joshbirk/1627326 to your computer and use it in GitHub Desktop.
Python Script to check GMail account
#!/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
# Use in your scripts as follows:
messages,unseen = gmail_checker('username','password')
print "%i messages, %i unseen" % (messages,unseen)
#stolen liberally from somewhere on the net
@KeizerDev
Copy link

Is there any way to add the title of the message to this code? I hope you can help me...

@sourav0101
Copy link

oh!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment