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)
#!/usr/bin/python
import poplib,getpass

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

Leave a Reply

Your email address will not be published. Required fields are marked *