topamax once a day

Raspberry Pi Physical Gmail Notifier

This tutorial will demonstrate how to easily turn your Raspberry Pi into a physical Gmail notifier, in only 10 lines of python! If the configured Gmail account has unread messages, the LED will be illuminated, otherwise dim.  The project was inspired by the Arduino/Mac version by J4mie adapted for use on the Raspberry Pi.

Here is a diagram of the wiring of the LED with a 330 ohm resistor in series (created with Fritzing):


The python script uses the feedparser module to simplify interaction with Gmail and the RPi.GPIO module to control the GPIO pins. The easiest way to install these is using the python pip package manager. If you don’t have it installed, you can install the pip package manager using apt-get. In a terminal on the Pi:

EDIT: For and newer, the Python development headers (python2.7-dev) are also required:

sudo apt-get install python-pip python2.7-dev

Next, for pip to work correctly you will need to update to a newer version of distribute using easy_install:

sudo easy_install -U distribute

Then install the feedparser and GPIO modules with pip:

sudo pip install feedparser RPi.GPIO

Once the pre-requisites have been installed, download , or copy and paste the following Python script to the Raspberry Pi:

The final step is to configure the script to run every minute as a cron job. To do so, open the global crontab for editing:

sudo crontab -e

Then add this line to the end of the file (adjust to the location of the python script):

* * * * * python /home/pi/

That’s it! From now on, cron will execute the script once every minute.  If you have unread messages, the GPIO pin will be pulled high, lighting the LED, otherwise, it will be disabled, dimming the LED.


  • Followed your instructions exactly, and I’m getting “SyntaxError: invalid syntax” at the colon at the end of “if newmails > 0: ”

    I’ve tried removing the colon, and then it SyntaxError’s again at the next line at the end of GPIO in “GPIO.output(GPIO_PIN, True)”…

    frustrating, it’d be great if I could get this to work, looks great!

    • I suspect your problem is in the line above the if statement… The colon is needed for valid Python syntax. Try adding print newmails above the if statement to check the return value from the feedparser function call.

  • ource/py_gpio.c:23:20: fatal error: Python.h: No such file or directory

    compilation terminated.

    error: command ‘gcc’ failed with exit status 1

    • Looks like you are missing the Python development headers… its seems they are not included by default in the newest Raspbian release. Install them like this:
      sudo apt-get install python-dev
      Then re-run the pip installer:
      sudo pip install feedparser RPi.GPIO
      Thanks for catching the error… I have updated the tutorial to reflect the changes!

      • Marc

        Minor clarification: I had the same problem, but I had to fix it by installing python2.7-dev (not python-dev).

        Also, in order for pip to function properly (requires >=0.6.27), I had to run “easy_install -U distribute” before the above commands to update it.

        Great RasPi posts, Michael!

        • Hi Marc,
          Thanks for pointing out this issue… The article has been updated accordingly!

  • Ben

    Thank you very much for this article — there are a number of similar articles that are wrong, but this worked great for me!

    • Glad to hear you found it useful Ben!

  • Dan

    Just FYI, on the latest release it looks like the GPIO states are not persistent. So as soon as the python script exits, the light goes out. This took me a while to figure out, but hopefully will help others!

    • Thanks for sharing Dan, at the time of the writing, the states remained persistent after script exit!

  • Nicolas

    Hi everyone,
    Can someone please help me : I’ve got this when trying to debug : “ImportError : No module named feedparser”
    I’m real beginner in the world of RPi and I’m french, so please excuse my poor english!!
    Thank you in advance!

    • Nicolas

      Seems I forgot to run “sudo pip install feedparser RPi.GPIO” as above ^^

      • Nicolas

        “AttributeError: ‘module’ object has no attribute ‘setmode'”

  • Jack Langstone

    When i enter ‘$ sudo python’
    it says

    File “”, line 5, in
    NameError: name ‘GPIO’ is not defined

    please help 🙂

    • Hi Jack, are you importing the RPi.GPIO as GPIO? If your import statement uses the default naming (ie import RPi.GPIO instead of import RPi.GPIO as GPIO) this would cause your NameError above.

  • Pingback: how to email snapshot from raspberry pi with a webcam | Rants, grunts and chants()

  • Andrei

    I whant to know how you connected the wires. because in the picture I see no resistor.
    A scheme it would be very helpful. Thanks!

  • Hi Michael.
    I took your great starting point to build a notifier which announces the senders of unread emails using Morse Code.

    Good fun mixing leading- and trailing-edge technologies!

    Read about it here:


    • Glad to hear you found it useful! Also, thanks for sharing your Morse Code project… very nice work!

  • Pingback: Morse Code Gmail Notifier #piday #raspberrypi @Raspberry_Pi « adafruit industries blog()

  • Pingback: LearnGrow LLC()

  • How do you connect the LED ? Directly without resistance ?

  • Pingback: Ten pimped-out projects for the Raspberry Pi | AyeITech()

  • Hi chatainsm, the LED is connected to the Pi with a 330 ohm resistor in series. I added a Fritizing diagram to the article for clarification.

  • Tommy Hill

    As soon as I add the Python Script to the Raspberry Pi, and run it, I get a syntax error as follows: “SyntaxError: invalid character in identitfier”. It also highlights the dot in RPi.GPIO. What is wrong here??

  • Ron H

    I am getting the following error:
    AttributeError: ‘module’ object has no attribute ‘parse’

  • R L

    Does the resistor have to be 300 ohm or will it work with 200ohm

  • Praveen

    Hi Michael 🙂 firstly thanks for all the guides. Very helpful. However, i’m faced with a error.

    syntax error near unexpected token `GPIO_PIN,

    This appears when i paste Huge chunk of python script. What does this mean and what do it do now?

  • bob31

    Hey, I like the project but when i easy_install, it doesnt work. Im not sure howto fix this.

  • Pingback: Raspberry Pi E-mail Notifier Using LEDs | linuxtor耳朵()

  • jimbo

    Got this working with GPIO but it doesn’t find the shell script when I run it with ‘shell’ or ‘bash’. Should the scripts be in the same directory as the program ( or in the /home/pi directory? I don’t find them in either place.

  • Hi,

    Could u post the code in c for email notifier project on raspberry pi?



  • Owen

    Great! Sounds great! One small problem: I have followed all the steps, but it says ImportError: No module named RPi.GPIO

  • Richard Thompson

    A beginner here: upon trying “sudo easy_install -U distribute”, I get serveral lines of error message ending with: ” raise ImportError(“Entry point %r not found” ” ((group, name),) ImportError: Entry point (‘console_scripts’, ‘easy_install’) not found
    I looked in /usr/local/bin and both easy_install and easy_install2.7 are shown as present. What does this mean? Thanks

  • Pingback: Contrôle d’un dispositif basse tension via Raspberry Pi |

  • Great tutorial. Do you know how we would use feedparser to find the email subject. I want to run a command when I email a new gmail inbox I’ve set up. This way, I can run the script from anywhere.

    • Sushrut

      please tell me if you get it

  • Yongseen Kim

    I dont know why cron job doesnt work…
    no response at all…
    except that everything works without a problem

  • Trevor ford

    Is there a way to make this work with hotmail?

  • Pingback: Notificador de Emails | Carlos Latorre()

  • rustybikes

    Thanks for this! I’d been playing with Adafruit’s code that runs in a While loop that checks every minute. For whatever reason, it would only run for a few hours and then stop working. Granted, remoting into the Pi to restart the Python script is trivial, but annoying. So, I started by asking Google about how to troubleshoot it. I’d figured I’d have to put a watchdog in cron to make sure it was always running. When I saw you running the Python code itself from cron, I had a pretty hard facepalm moment. That was.. uh.. fun? Ha.

    I’ve built on the idea (Gmail checker), and have it not only checking, but also telling me how many unread messages are in my inbox, using a 7-segment display (also from Adafruit). Here’s a brief clip showing it in action: – it’s running once a minute via cron, based on your example.

    Thanks again!

  • Spatimouth01

    Is it possible to setup a encrypted password in the python script?

  • Alex Singleton

    I was jsut wondering if you had any idea of how you would go about coding the Raspberry Pi to send a SMS message to your phone if you recieve an ‘Out of Office’ after sending an email to someone? Or getting the LED to turn on if getting that same ‘Out of Office’ response?

    • DigitalBlueeye

      I can help with that, Im working on a similar program and after a lot of thought, i figured out the easiest and free way to do it is to use a sender/reciever setup thru python on the py, sending to your phone via its email , the way i figured this out is i sent a text to my email ( just insert email instaid of number, no smartphone needed) and then used the sender address ( ex [email protected]) and it works fine, just as fast as sms phone to phone

      so use a email setup in python such at smmtp to text your phone if something happens that you list.

  • DigitalBlueeye

    hey i tried this code out from this website and also adafruits identical tutorial, when i run the code i get a import error on feedparser, i checked spelling, updated the pi, etc, so far no suscess, im planning to use it to control a python program and servo, but this is in the way so if anyone can help i would much appriciate it! even just refer me to a similar module to use or something, spent at least two hours on this issue with no luck…

    • DigitalBlueeye

      Asap would be great btw

  • Ian Hetherington

    Works a treat thanks, I have the pi doing something when an email lands in a certain folder. But…… can you get it to mark the mail as read, otherwise it just keeps repeating. any help greatly appreciated

  • I’m not new to python or the Pi, and everything runs fine, but the LED is NOT
    lighting up to its full brightness when the code is executed. Yes, I’m on the correct
    Pin and Yes, I had to add sudo so it would execute correctly. So what’s wrong?
    Yes, the LED is dim.

  • Hey, Micheal, maybe gmail handles your newmails line differently now!?

  • Shay Hamblin

    Just wanted to thank you for this, Adafruit has a similar tutorial but it didn’t work for me but this did. Small note, I did have to enable “less secure devices to connect” in google settings, but once I did, it worked great!

  • Pingback: Build an LED Indicator with a Raspberry Pi (for Email, Weather, or Anything) – 6 Ters()