Skip to content

Instantly share code, notes, and snippets.

@jfcarr
Created July 4, 2017 14:18
Show Gist options
  • Save jfcarr/07dfc5717f157816da99aacabaed7eb2 to your computer and use it in GitHub Desktop.
Save jfcarr/07dfc5717f157816da99aacabaed7eb2 to your computer and use it in GitHub Desktop.
Show unread email count via IMAP.
#!/usr/bin/python
import imaplib
import sys
class MailHandler:
def CheckUnread(self, username, password):
imapConnection = imaplib.IMAP4_SSL('your.mailserver.com',993)
imapConnection.login (username, password)
imapConnection.select()
mailCount = len(imapConnection.search(None, 'UNSEEN')[1][0].split())
if mailCount > 0:
print str(mailCount) + ' : ' + username
MyMail = MailHandler()
MyMail.CheckUnread('john.doe@mailserver.com','password')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment