How To: Make a Gmail Notifier in Python

Make a Gmail Notifier in Python

In this article, I'll show you how to make a simple Gmail notifier. Python can do various things in terms of notifications; sending commands to an Arduino unit, playing sounds, opening windows, etc. The code below simply plays some music, but the possibilities of notification methods are endless. If you aren't familiar with python, there are many sites with tutorials like this one, or this one

What You Need

  • A Gmail account
  • Python 2.7 or later, with feedparser installed (get it here)
  • A little python experience

The Code

For this program, you need two pieces of code. The first one parses your account data and sends it to Gmail, then checks for mail. The second portion runs this program every second, and notifies you when a new email is present. The code I wrote simply plays three notes using winsound (it will only work on Windows computers).

First portion-

import sys, feedparser, winsound
#Here, we import modules needed for this program
#We assign variables with values. Fill in your username and password
def mail(checker):
    email = int(feedparser.parse(
        PROTO + USERNAME + ":" + PASSWORD + "@" + SERVER + PATH
#parses your account data and sends it to gmail
    if email > 0:
        newEmail = 1
        newEmail = 0
    #checks for mail

    if newEmail==1:
         winsound.Beep(440, 500)
         winsound.Beep(370, 500)
         winsound.Beep(392, 500)

#plays sound if email present

Second portion-    

import parser2, time
#import modules
#set variable
while True:
#re-run program to infinity, every ten seconds. Change the "time.sleep(seconds to wait) variable if you want a longer/shorter check interval.

Other Possibilities

I simply have it playing sound, but it would take all of three seconds to set up an Arduino interface, and in turn, have the Arduino light up a bulb, ring a physical bell, or any number of things. You could even have python speak the email text, or reply to the sender. Use your imagination! :)



Want to start making money as a white hat hacker? Jump-start your hacking career with our 2020 Premium Ethical Hacking Certification Training Bundle from the new Null Byte Shop and get over 60 hours of training from cybersecurity professionals.

Buy Now (90% off) >

Other worthwhile deals to check out:

Join the Next Reality AR Community

Get the latest in AR — delivered straight to your inbox.


Awesome! :D I want to try to make a *nix verison of this. This is a coincidence, I was just messing around with the Google APIs all yesterday. GTalk, and GVoice are very fun ones too^_^. I'm quite angry that the G+ API isn't even released fully, yet. You can only read posts and view profile lame :(.

nice! google will even send text messages for you, through python :D

Scumbag Google -

I can not run second part of the program.
Error message come like this.
Traceback (most recent call last):
File "C:/Users/IM CGTTI ASUS/PycharmProjects/opencv_test/", line 1, in <module>
import parser2, time
ModuleNotFoundError: No module named 'parser2'
I tried all day. please help me.

Share Your Thoughts

  • Hot
  • Latest