E-mail notifier
Years ago, I made an e-mail notifier with Raspberry pi.
Years ago, I made an e-mail notifier using a raspberry pi and two LEDs. The Raspberry pi was integrated with my gmail account. When there was a new e-mail, it glew a Red Led, when there was no new mail, it turned on a Green LED.
Components:
Red LED x 1
Green LED x 1
Breadboard x 1
100 ohms resistor x 2
Jumper wires- Male to Female
Raspberry Pi 3B+ x 1
Connections:
Raspberry pi | Components
GPIO 18 | Positive side of Green LED through a 100K resistor.
GPIO 15 | Positive side of Red LED through a 100K resistor.
GND | GND
Code:
At first, I installed pip
sudo apt-get install python-pip
Then I installed a python package named IMAPClient
sudo pip install imapclient
Then I ran the following python script.
import RPi.GPIO as GPIO, imaplib, time
DEBUG = 1
USERNAME = "e-mail id" # just the part before the @ sign, add yours here
PASSWORD = "password"
NEWMAIL_OFFSET = 0
MAIL_CHECK_FREQ = 60 # check mail every 60 seconds
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GREEN_LED = 18
RED_LED = 15
GPIO.setup(GREEN_LED, GPIO.OUT)
GPIO.setup(RED_LED, GPIO.OUT)
M = imaplib.IMAP4_SSL('imap.gmail.com','993')
sessionValid = True
try:
M.login(USERNAME, PASSWORD)
print ("LOGIN SUCCESSFULL")
except Exception as e:
print (e)
print ("LOGIN FAILED!!! ")
sessionValid= False
while sessionValid:
M.select()
newmails = len(M.search(None, 'UnSeen')[1][0].split()) # from http://stackoverflow.com/a/3984850
if newmails > NEWMAIL_OFFSET:
GPIO.output(GREEN_LED, True)
GPIO.output(RED_LED, False)
print ("New mail")
else:
GPIO.output(GREEN_LED, False)
GPIO.output(RED_LED, True)
print ("No new mail")
time.sleep(MAIL_CHECK_FREQ) .

Discussion (1 comment)