-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimapMails.py
More file actions
51 lines (40 loc) · 1.21 KB
/
imapMails.py
File metadata and controls
51 lines (40 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
from imapclient import IMAPClient
import time
import configVal
#import RPi.GPIO as GPIO
DEBUG = True
HOSTNAME = 'imap.gmail.com'
USERNAME = configVal.details["username"]
PASSWORD = configVal.details["password"]
MAILBOX = 'Inbox'
NEWMAIL_OFFSET = 1 # my unread messages never goes to zero, yours might
MAIL_CHECK_FREQ = 60 # check mail every 60 seconds
#GPIO.setwarnings(False)
#GPIO.setmode(GPIO.BCM)
#GREEN_LED = 18
#RED_LED = 23
#GPIO.setup(GREEN_LED, GPIO.OUT)
#GPIO.setup(RED_LED, GPIO.OUT)
def loop():
server = IMAPClient(HOSTNAME, use_uid=True, ssl=True)
server.login(USERNAME, PASSWORD)
if DEBUG:
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'])
if DEBUG:
print "You have", newmails, "new emails!"
if newmails > NEWMAIL_OFFSET:
print "emails undread here"
time.sleep(MAIL_CHECK_FREQ)
if __name__ == '__main__':
try:
print 'Press Ctrl-C to quit.'
while True:
loop()
finally:
#GPIO.cleanup()
print "end here"