Skip to content

Instantly share code, notes, and snippets.

@mrtazz
Created September 18, 2012 04:06
Show Gist options
  • Select an option

  • Save mrtazz/3741193 to your computer and use it in GitHub Desktop.

Select an option

Save mrtazz/3741193 to your computer and use it in GitHub Desktop.

Revisions

  1. mrtazz created this gist Sep 18, 2012.
    20 changes: 20 additions & 0 deletions imap_check.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    #!/usr/bin/env python
    """
    small script to check for unread count on imap inbox
    """
    import imaplib

    IMAPSERVER = ''
    USER = ''
    PASSWORD = ''

    try:
    mail = imaplib.IMAP4_SSL(IMAPSERVER)
    mail.login(USER, PASSWORD)
    mail.select("inbox", True) # connect to inbox.
    return_code, mail_ids = mail.search(None, 'UnSeen')
    count = len(mail_ids[0].split(" "))
    except:
    count = 0

    print count