gMail - New email count
Posted: Mon Mar 07, 2016 8:21 am
Hi,
Here the script I used for counting new email(s) in my gMail accounts:
This script put the number of new email(s) in a variable. If the script is not able to connect to your gMail account, 'Err' will be added into the variable.
Configuration:
Joël
Here the script I used for counting new email(s) in my gMail accounts:
- Code: Select all
import imaplib
import re
# gMail retreiving the number of new email(s)
def gmail_checker(username, password):
# Connection to the imap server
conn = imaplib.IMAP4_SSL('imap.gmail.com')
try:
# Log to the imap server
conn.login(username, password)
status, info = conn.status('INBOX','(MESSAGES UNSEEN)')
conn.logout()
# Parse received info.
mess = int(re.search('MESSAGES\s+(\d+)', info[0]).group(1))
new = int(re.search('UNSEEN\s+(\d+)' , info[0]).group(1))
except:
# We have an error, we signal it
mess = -1
new = 0
return (mess, new)
# Variable ID
kVAR_GMAIL = xxx
# Get number of new email
mess, new = gmail_checker('xxx@gmail.com', 'xxx')
counter = str(new) if mess > 0 else u"Err"
# Update variable
indigo.variable.updateValue(kVAR_GMAIL, value=counter)
This script put the number of new email(s) in a variable. If the script is not able to connect to your gMail account, 'Err' will be added into the variable.
Configuration:
- > Add the script in a schedule (or other);
> Replace all 'xxx' with your own configuration;
> Activate "Allowing less secure apps to access your account" in your gMail account if is not already done: LINK
Joël