Created
April 27, 2015 05:55
-
-
Save brennen/cacd0f1a08f20c7226c4 to your computer and use it in GitHub Desktop.
checkmail_simple.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from imapclient import IMAPClient | |
import sys | |
import time | |
DEBUG = True | |
HOSTNAME = 'imap.gmail.com' | |
USERNAME = 'your username here' | |
PASSWORD = 'your password here' | |
MAILBOX = 'Inbox' | |
NEWMAIL_OFFSET = 1 # my unread messages never goes to zero, yours might | |
MAIL_CHECK_FREQ = 60 # check mail every 60 seconds | |
def loop(): | |
server = IMAPClient(HOSTNAME, use_uid=True, ssl=True) | |
server.login(USERNAME, PASSWORD) | |
print('Logging in as ' + USERNAME) | |
select_info = server.select_folder(MAILBOX) | |
print('%d messages in INBOX' % select_info['EXISTS']) | |
folder_status = server.folder_status(MAILBOX, 'UNSEEN') | |
newmails = int(folder_status['UNSEEN']) | |
print "You have", newmails, "new emails!" | |
time.sleep(MAIL_CHECK_FREQ) | |
if __name__ == '__main__': | |
try: | |
print 'Press Ctrl-C to quit.' | |
while True: | |
loop() | |
finally: | |
sys.exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment