gmail poplib python 2.7

Gmail works best in SSL mode. Find out the number of emails in your gmail inbox.

  1. Credentials are input from the keyboard, even with an extra example of hiding the password as opposed to placing the credentials in the program (which would be good for crontab scripts)
import poplib,getpass

poPserver = poplib.POP3_SSL("", 995)
poPuser = raw_input('Username:')
print poPserver.user(poPuser)
print poPserver.pass_(getpass.getpass())
messageCount = len(poPserver.list()[1])
print messageCount, "messages"