Skip to content

Instantly share code, notes, and snippets.

@dloman
Created October 16, 2013 17:47
Show Gist options
  • Save dloman/7011907 to your computer and use it in GitHub Desktop.
Save dloman/7011907 to your computer and use it in GitHub Desktop.
Python script for getting number of new messages on an exchange server
#!/usr/bin/python
##Gets Number of New Emails
##Daniel Loman 10/15/2013
import getpass, imaplib, pickle
########################################################################################
########################################################################################
def GetNumberOfMessages():
Mailbox = imaplib.IMAP4("server.address")
AuthenticationToken = pickle.load(open(AuthFileLocation,'rb'))
Mailbox.authenticate("NTLM", AuthenticationToken)
Mailbox.select(readonly=True)
Typ, MessageNums = Mailbox.search(None,'UNSEEN')
if '' in MessageNums:
MessageNums.remove('')
return len(MessageNums)
########################################################################################
########################################################################################
if __name__ == "__main__":
print 'Number Of New Messages =',GetNumberOfMessages()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment