# Raspberry Pi E-mail Notifier Using LEDs

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/000/719/medium800/raspberry_pi_IMG_46501.jpg?1396765310)

# Overview

Raspberry Pi’s popularity makes things so easy that it is almost scary. I set forth on a simple starter project of having the Raspberry Pi show me when new Gmail messages arrive.&nbsp;After some searching, it seems that lots of people are already talking about how to do this and there are some great examples. [Michael over at MitchTech](http://mitchtech.net/raspberry-pi-physical-gmail-notifier/ "Link: http://mitchtech.net/raspberry-pi-physical-gmail-notifier/")&nbsp;had the most ready to go code which I pilfered from.&nbsp;

This project uses two LEDs one green and one red. When a new mail message has arrived the green LED will illuminate. When there are no unread messages the red LED will illuminate.

# To Follow This Tutorial You Will Need

- [Pi T-Cobbler Plus,](https://www.adafruit.com/product/2028)&nbsp;[Pi Cobbler Plus for Model B+ / Pi 2](https://www.adafruit.com/products/2029)&nbsp;or the original&nbsp;[Pi Cobbler](https://www.adafruit.com/product/914)
- [(1) Full sized breadboard](https://www.adafruit.com/product/239)
- [Hook-up Wire](https://www.adafruit.com/index.php?main_page=adasearch&q=hook-up+wire+spool "Link: https://www.adafruit.com/index.php?main\_page=adasearch&q=hook-up+wire+spool")
- [A Raspberry Pi](https://www.adafruit.com/?q=raspberry%20pi)&nbsp;(compatible with all 26pin and 40pin Pi releases to date)

HINT: We suggest purchasing the [Raspberry Pi 3 Model B Starter Pack](https://www.adafruit.com/product/3334) along with a [Raspberry Pi](https://www.adafruit.com/product/3775) which includes all the necessary materials for this tutorial.

# Raspberry Pi E-mail Notifier Using LEDs

## Wire the Cobbler to the LEDs

Modern Raspberry Pi's use a 40-pin header. The first generation of Pi's used a 26-pin header. This tutorial works with all of these versions using the same code and GPIO pins. We have provided wiring examples of both types using the same GPIO pins (#18 and #23).

When connecting the GPIO cable, make sure that you note the red or white wire on the ribbon, that's pin #1 of the cable. That end goes at the side closest to the SD Card and is labeled&nbsp; **P1** on the Pi. The other side connects to the cobbler and can only be inserted one way due to the notch in the cable.  
  
Place the cobbler onto the bread board straddling the center line. Connect the&nbsp; **GND** pin (ground) to the blue power rail on the side of the breadboard. You'll need two resistors (any values&nbsp;from 330 ohm up to 1000 ohm are fine).

Connect the first resistor to the cobbler row marked&nbsp; **#18** , and the other end to a row that isn't used by the cobbler.

Connect the second resistor to the cobbler row marked # **23** and the other end to another empty row.

# Raspberry Pi Cobbler Plus - 40-pin for Pi v2, v3, Zero
![](https://cdn-learn.adafruit.com/assets/assets/000/024/094/medium800/raspberry_pi_email_blinkies_bb.png?1427489683)

# Raspberry Pi Cobber - 26-pin - for Pi v1 only
![](https://cdn-learn.adafruit.com/assets/assets/000/024/147/medium800/raspberry_pi_little_cobbler_bb.png?1427733019)

# Step-by-Step Hookup on a 26-pin Pi Cobbler
![](https://cdn-learn.adafruit.com/assets/assets/000/000/716/medium800/raspberry_pi_resistors.jpg?1396765277)

Now grab a red LED and a green LED. Look for the long pins on the LEDs; those are the positive (+) legs.

Connect the long (+) leg of the red LED to the resistor connected to&nbsp; **#23** &nbsp;(GPIO #23), and the long leg of the green LED to&nbsp;the resistor connected to&nbsp; **#18**.

The short legs plug into the blue striped rail on the side of the breadboard.

![](https://cdn-learn.adafruit.com/assets/assets/000/000/720/medium800/raspberry_pi_leds.jpg?1396765317)

The above images are for an original Pi Cobbler. For newer, 40-pin models like the A+/B+/Pi 2, you'll probably want to do something more like this, using wires to connect the resistors to the LEDs (click for a larger image):

That's it! You've just wired two LEDs with current-limiting resistors to the GPIO pins of the Pi.

# Raspberry Pi E-mail Notifier Using LEDs

## Necessary Packages

# Update Your Pi to the Latest Raspbian
Your Pi will need to be running the latest version of Raspbian. This tutorial was written using Raspbian Stretch (Nov. 2018). Checkout our guide for&nbsp;[Preparing an SD Card for your Raspberry Pi](https://learn.adafruit.com/adafruit-raspberry-pi-lesson-1-preparing-and-sd-card-for-your-raspberry-pi)&nbsp;if you have not done so already. After the installation is complete be sure and run the following commands to make sure your packages are up to date.&nbsp;

```
$ sudo apt-get install update -y
$ sudo apt-get install upgrade -y
```

# Install pip3
pip3 is already installed with a full Raspbian installation, but the Raspbian Lite does not include pip3 so it needs to be installed as shown below.

```
$ sudo apt-get install python3-pip

```

# Install adafruit-blinka
```
$ sudo pip3 install adafruit-blinka
```

# Install imapclient
```
sudo pip3 install imapclient
```

# Raspberry Pi E-mail Notifier Using LEDs

## Python Script

![](https://cdn-learn.adafruit.com/assets/assets/000/000/718/medium800/raspberry_pi_IMG_46501.jpg?1396765307)

Now you're ready to download some Python code and check your Gmail account. The following python script can be downloaded directly onto your raspberry pi, customized with your email settings and executed to illuminate the LEDs.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Raspberry_Pi_E-mail_Notifier_Using_LEDs/Raspberry_Pi_E-mail_Notifier_Using_LEDs.py

# Download the Code
Let's put this file right in your home directory for simplicity. The wget command makes this easy.

```
$ cd
$ wget https://raw.githubusercontent.com/adafruit/Adafruit_Learning_System_Guides/master/Raspberry_Pi_E-mail_Notifier_Using_LEDs/Raspberry_Pi_E-mail_Notifier_Using_LEDs.py
```

# Customize Mail Variables
Don't forget to set the `USERNAME` and `PASSWORD` to match your GMail account. (Remember, if you're using two-factor authentication under GMail, you'll need to generate an [application-specific password](https://support.google.com/mail/answer/1173270?hl=en) for this. If you're using a different e-mail provider, you may need to check their documentation for what `HOSTNAME` to use. It's usually something like `imap.youremailproviderhere.com`.)

Finally, my INBOX never goes to zero unread messages. We have a variable called `NEWMAIL_OFFSET` which you can customize to whatever your current unread message count is. When running this python script there will be a number output to the console showing the current number of unseen messages.

# Running the Code
```
$ python3 ./Raspberry_Pi_E-mail_Notifier_Using_LEDs.py
```

Send yourself some emails to see the green LED light up!

You can stop the script at any time by pressing **Ctrl-C**.

# Raspberry Pi E-mail Notifier Using LEDs

## Remote SSH

As a first step, you'll want a terminal on your Pi. There are a variety of options, explored in more detail in the [Getting a Terminal on Your Raspberry Pi](../../../../what-is-the-command-line/getting-a-terminal-on-your-raspberry-pi) section of our [introduction to the command line](../../../../what-is-the-command-line/overview):

1. Plug in an HDMI monitor and keyboard
2. [Use a console cable](../../../../adafruits-raspberry-pi-lesson-5-using-a-console-cable/overview)
3. [Log in via **S** ecure **SH** ell (SSH)](../../../../adafruits-raspberry-pi-lesson-6-using-ssh)

Since this project uses the GPIO pins for its own purposes, you'll want to choose between working directly on the Pi (this is fine if you're already set up!) or connecting via SSH (a good idea if you don't have an extra monitor / input devices laying around, and want to work from the comfort of your desktop or laptop).

Examples here will assume a working Raspbian installation with an SSH connection. Not sure how to get started?

For installating Raspbian, check out our [guide to preparing an SD card for the Pi](../../../../adafruit-raspberry-pi-lesson-1-preparing-and-sd-card-for-your-raspberry-pi/overview). If you need help finding the Pi on your network and connecting to it, check out our Pi Finder utility.

[Adafruit Pi Finder](https://github.com/adafruit/Adafruit-Pi-Finder)
...and here's our [guide to using SSH](../../../../adafruits-raspberry-pi-lesson-6-using-ssh).

# Raspberry Pi E-mail Notifier Using LEDs

## Prepare Python

In order for our Python code to work, we'll want to make sure a few libraries are installed.  
  
First, from either the keyboard/monitor or SSH console type in:

```
sudo apt-get install python-pip
```

![](https://cdn-learn.adafruit.com/assets/assets/000/024/090/medium800/raspberry_pi_Screenshot-2015-03-27-10_24_13.png?1427473557)

...you'll be asked if you want to continue. Type "Y" for yes, and hit enter.

![](https://cdn-learn.adafruit.com/assets/assets/000/024/091/medium800thumb/raspberry_pi_screencast-2015-03-27-10_24_35.jpg?1448317266)

This part will probably take a little while.

Then you can install the&nbsp;[IMAPClient](http://imapclient.readthedocs.org/en/latest/) Python library, which lets Python talk to most e-mail services:

```
sudo pip install imapclient
```

![](https://cdn-learn.adafruit.com/assets/assets/000/024/092/medium800/raspberry_pi_Screenshot-2015-03-27-11_01_04.png?1427477493)

Danger: 

The current version of the script should actually work with any e-mail provider that provides [IMAP](https://en.wikipedia.org/wiki/Internet_Message_Access_Protocol) access. A few useful links:

- [Yahoo! Mail IMAP Settings](https://help.yahoo.com/kb/mobile/imap%C2%A0settings-yahoo-mail-sln4075.html)
- [Hotmail / Outlook.com IMAP Settings](http://www.howto-outlook.com/howto/accountsettings.htm#outlookcom-imap)
- [iCloud: Mail server settings for email clients](https://support.apple.com/en-us/HT202304)

I **f you have two-factor authentication enabled on your GMail account** , you'll need to generate an application-specific password to use IMAP. I[followed Google's detailed instructions](https://support.google.com/mail/answer/1173270?hl=en) and was up and running in no time.

Not sure if you have two-factor auth enabled? That probably means you don't, so don't worry about it for now.


## Featured Products

### Raspberry Pi Starter Pack

[Raspberry Pi Starter Pack](https://www.adafruit.com/product/3049)
You're going to work hard with your Raspberry Pi 2 Model B or Raspberry Pi 1 Model B+. &nbsp;You're going to have to solder, code, and Linux your Maker heart out. &nbsp;That's why we've tried to make it as easy as possible to start...

In Stock
[Buy Now](https://www.adafruit.com/product/3049)
[Related Guides to the Product](https://learn.adafruit.com/products/3049/guides)
### Raspberry Pi 3 - Model B+ - 1.4GHz Cortex-A53 with 1GB RAM

[Raspberry Pi 3 - Model B+ - 1.4GHz Cortex-A53 with 1GB RAM](https://www.adafruit.com/product/3775)
The Raspberry Pi 3 Model B is the most popular Raspberry Pi computer made, and the Pi Foundation knows you can always make a good thing _better_! And what could make the Pi 3 better? How about a&nbsp;_faster_ processor, 5 GHz WiFi, and updated Ethernet chip with PoE capability?...

In Stock
[Buy Now](https://www.adafruit.com/product/3775)
[Related Guides to the Product](https://learn.adafruit.com/products/3775/guides)
### Full Sized Premium Breadboard - 830 Tie Points

[Full Sized Premium Breadboard - 830 Tie Points](https://www.adafruit.com/product/239)
This is a 'full-size' premium quality breadboard, 830 tie points. Good for small and medium projects. It's 2.2" x 7" (5.5 cm x 17 cm) with a standard double-strip in the middle and two power rails on both sides. You can pull the power rails off easily to make the...

In Stock
[Buy Now](https://www.adafruit.com/product/239)
[Related Guides to the Product](https://learn.adafruit.com/products/239/guides)
### 5V 2.5A Switching Power Supply with 20AWG MicroUSB Cable

[5V 2.5A Switching Power Supply with 20AWG MicroUSB Cable](https://www.adafruit.com/product/1995)
Our all-in-one 5V 2.5 Amp + MicroUSB cable power adapter is the perfect choice for powering single-board computers like Raspberry Pi, BeagleBone, or anything else that's power-hungry!

This adapter was specifically designed to provide 5.25V, not 5V, but we still call it a 5V USB...

In Stock
[Buy Now](https://www.adafruit.com/product/1995)
[Related Guides to the Product](https://learn.adafruit.com/products/1995/guides)
### Assembled Pi Cobbler Plus - Breakout Cable

[Assembled Pi Cobbler Plus - Breakout Cable](https://www.adafruit.com/product/2029)
The Raspberry Pi B+ / Pi 2 / Pi 3 / Pi 4 / Pi 5 has landed on the Maker World like a 40-GPIO pinned, quad-USB ported, credit card sized bomb of DIY joy. And while you can use most of our great Model B accessories by hooking up our [downgrade...](https://www.adafruit.com/product/1986)

In Stock
[Buy Now](https://www.adafruit.com/product/2029)
[Related Guides to the Product](https://learn.adafruit.com/products/2029/guides)
### Assembled Pi T-Cobbler Plus - GPIO Breakout

[Assembled Pi T-Cobbler Plus - GPIO Breakout](https://www.adafruit.com/product/2028)
 **This is the assembled version of the Pi T-Cobbler Plus. &nbsp;It only works with the Raspberry Pi Model Zero, A+, B+, Pi 2, Pi 3, Pi 4, and Pi 5!** (Any Pi with 2x20 connector)  
  
The Raspberry Pi has landed on the Maker World like a 40-GPIO pinned, quad-USB ported,...

In Stock
[Buy Now](https://www.adafruit.com/product/2028)
[Related Guides to the Product](https://learn.adafruit.com/products/2028/guides)
### Diffused Red 10mm LED (25 pack)

[Diffused Red 10mm LED (25 pack)](https://www.adafruit.com/product/845)
Need some big indicators? We are big fans of these huge diffused red LEDs. They are fairly bright so they can be seen in daytime, and from any angle. They go easily into a breadboard and will add that extra zing to your project.

- Pack of 25 diffused red LEDs
- 10mm...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/845)
[Related Guides to the Product](https://learn.adafruit.com/products/845/guides)
### Diffused Green 10mm LED (25 pack)

[Diffused Green 10mm LED (25 pack)](https://www.adafruit.com/product/844)
Need some big indicators? We are big fans of these huge 10mm diffused green LEDs. They are fairly bright so they can be seen in daytime, and from any angle. They go easily into a breadboard and will add that extra zing to your project.

- Pack of 25 diffused green LEDs
- 10mm...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/844)
[Related Guides to the Product](https://learn.adafruit.com/products/844/guides)

## Related Guides

- [Speech Synthesis on the Raspberry Pi](https://learn.adafruit.com/speech-synthesis-on-the-raspberry-pi.md)
- [Analog Inputs for Raspberry Pi Using the MCP3008](https://learn.adafruit.com/reading-a-analog-in-and-controlling-audio-volume-with-the-raspberry-pi.md)
- [Capacitive Touch Sensors on the Raspberry Pi](https://learn.adafruit.com/capacitive-touch-sensors-on-the-raspberry-pi.md)
- [Playing sounds and using buttons with Raspberry Pi](https://learn.adafruit.com/playing-sounds-and-using-buttons-with-raspberry-pi.md)
- [Adafruit's Raspberry Pi Lesson 10. Stepper Motors](https://learn.adafruit.com/adafruits-raspberry-pi-lesson-10-stepper-motors.md)
- [Adafruit's Raspberry Pi Lesson 12. Sensing Movement](https://learn.adafruit.com/adafruits-raspberry-pi-lesson-12-sensing-movement.md)
- [Node.js Embedded Development on the Raspberry Pi](https://learn.adafruit.com/node-embedded-development.md)
- [LoRa and LoRaWAN Radio for Raspberry Pi](https://learn.adafruit.com/lora-and-lorawan-radio-for-raspberry-pi.md)
- [CircuitPython Libraries on Linux and Google Coral](https://learn.adafruit.com/circuitpython-on-google-coral-linux-blinka.md)
- [Basic Resistor Sensor Reading on Raspberry Pi](https://learn.adafruit.com/basic-resistor-sensor-reading-on-raspberry-pi.md)
- [Program an AVR or Arduino Using Raspberry Pi GPIO](https://learn.adafruit.com/program-an-avr-or-arduino-using-raspberry-pi-gpio-pins.md)
- [Adding Basic Audio Ouput to Raspberry Pi Zero](https://learn.adafruit.com/adding-basic-audio-ouput-to-raspberry-pi-zero.md)
- [Moonshine Voice Control on Raspberry Pi](https://learn.adafruit.com/moonshine-voice-control-on-raspberry-pi.md)
- [Circadian Pi Desk Light](https://learn.adafruit.com/circadian-pi-desk-light.md)
- [Matrix and 7-Segment LED Backpack with the Raspberry Pi](https://learn.adafruit.com/matrix-7-segment-led-backpack-with-the-raspberry-pi.md)
