Alert Mail Raspberry Pi


Temperatures above 80 °C can damage your raspberry pi.

Especially if your using your pi as a webserver, webcam-stream or as a display system, in a 24 hour-operation, you may want to get warned via Email. Getting a notification from your pi is pretty simple, just use the script below:

If you have any questions about the notification system or any other Pi Topic, feel free to comment.
Cheers Alex


27 thoughts on “Alert Mail Raspberry Pi

  1. Oke, i see your script, and now?


  2. Haha i know, but how, must i make it a .sh script?
    Where to put it?
    Is there extra software needed?
    How must i continue,..


    • You need to give it a .py Extension. You could put in the root or home directory (I would recommend). To Run: Sudo python name-of-script.py. You may want to autostart the script to:~/.config/lxsession/LXDE/autostart

      I hope this helps you out.


    • i got a error on line 21

      root@ruudberry:~# python temp.py
      File “temp.py”, line 21
      server.login(“raspberrypi”, “qwerty123”)
      IndentationError: unindent does not match any outer indentation level


  3. i don’t have a mail program running on the raspberry yet, maybe that is the 21 error.


  4. I would recommend you to copy the script from above in a new *.py file, because I’ve made a few changes, hopefully it’s now more clearly. Make sure to have the same indentation that I have.

    If this does not help, try this:

    Another reason why you got the “Server login error”, might be caused by a wrong username, password or server. If you could tell me your email provider, I could help you editing the script for your needs. Please let me know if you have any issues.

    You don’t need to have a mail program because we are importing the smpt library. 🙂


  5. :-))))))))

    Critical warning! The actual temperature is: 45.5

    It’s working!
    (i put it for the test to 10 degrees)

    Thanks for the support!

    Best regards,


    • We thank you for the help to improve the article. We hope you enjoy to work with the Raspberry Pi.

      Best regards,

      Michael from quaint project.


  6. Hi Alex,

    I have changed my password, it’s a little bit longer, but now i get the following error.

    File “/root/Mailalert.py”, line 25
    server.login(“123@gmail.com”, “&(“LN3KXJWLYQL0ZQPQrrKmGFqUOneq3OMUkKEBWxHP38SKkC3egrffIfq3”)
    SyntaxError: invalid syntax

    Can you tell me how to solve this issue?

    Thanks in advance.


    • Hey there,
      sorry for my verrrry late reply. It seems like I’ve missed your comment. The problem is that you have a quotation mark in your password and this is normally the beginning and ending of a string. If you still want to solve it you could put it like this:

      server.login(‘123@gmail.com’, ‘&(“LN3KXJWLYQL0ZQPQrrKmGFqUOneq3OMUkKEBWxHP38SKkC3egrffIfq3’)

      These single quotes have a higher priority than the quotation mark.

      Best Alex


  7. Is it possible to have more than 10 characters for password input?


  8. Pingback: Alert temperature and e-mail | Raspberry Pi stuff

  9. Hello, I know it’s not a recent post, but how does the script work if I launch it with autostart? Will it check température as it evolves ans then stop zone the alert is done, or will it just check the temp at startup ans stop whatever is thé result of the temp?
    Just to know if it’s better to do it in @reboot with cron or every hour. Yeah i’m a noob trying to figure things 🙂
    Thank you for this script, it’s the main thing I want to monitor on the rpi.


    • Hey there,
      thanks for you comment, you’ve luck this post is still active!

      there are basically two ways how you could do it.
      1. Modify the script to run a endless While loop with the condition true. This would run the script as long as the script is not interrupted. (The temperature would be checked every loop).

      2. You could make a cronjob that runs every 30 minutes (no need to reboot) and call the script. In my opinion this method would have the benefit that you wouldn’t get a view hundred mails in a really short time.

      Right now the Script the script starts and checks if the temperature is to high -> send mail, if not it simply ends the script.

      I hope my comment helps to solve all your questions! If not, feel free to reply again.



    • Hello, thank you! It’s a perfect answer. From my understanding of python it’s what I suspected ans what I checked after blowing on my rPi to play with the temp ans see the script had ended on the trial value :).
      So I made a cronjob every 30mn and it’s allright for my needs.
      Thanks for the answer and great website by the way, a little bit advanced for my level but that’s the way to learn :), already bookmarked.


    • Thanks so much for your kind words! I can tell you from all of our crew members that we all were once beginners with the Raspberry Pi. If you have any topic we could cover or wich meets your interests feel free to tell us. Thanks for bookmarking!


  10. Hi Codewarrior, I was able to get the script to work. Like it !
    Actually, I am also looking for a script that monitors several GPIO Ports and emails me when things change (NC/NO).
    I know there i a lot on the web, but there is also a lot of crap and stuff where people assume you are a top programmer and understand everything from nature. If I see something it crashes my Raspberry, or doesn’t do anything at all.

    Remarkable thing is, yours simply works !
    That’s why I use it now and was wondering if you can help me with the multiple NC/NO GPIOs monitoring.

    What it needs to do:
    – monitor a switch (open/closed) and email me about it.
    – monitor water level to prevent flooding and email me about it
    – stay “active” no cron jobs, no reboot, just like a background service.

    If you can help me or guide me to something that simply WORKS, I would appreciate it !


  11. Hi, please please help me. Im very new to RasPi and I´m trying to use your script with no success. What I did is first: nano notify.py, once there I added this script:


    import os
    import smtplib
    from email.mime.text import MIMEText

    At First we have to get the current CPU-Temperature with this defined function

    def getCPUtemperature():
     res = os.popen(‘vcgencmd measure_temp’).readline()

    Now we convert our value into a float number

    temp = float(getCPUtemperature())

    Check if the temperature is abouve 60°C (you can change this value, but it shouldn’t be above 70)

    if (temp >60):
     # Enter your smtp Server-Connection
     server = smtplib.SMTP(‘smtp.gmail.com’, 587)
     #if your using gmail: smtp.gmail.com
     # Login
     server.login(“jolimk@gmail.com”, “MYACTUALPASSWORD”)
     # Now comes the Text we want to send:
     value = “URGENTE! La temperatura es: ” + getCPUtemperature()
     msg = MIMEText(value)
     # The Subject of your E-Mail
     msg[‘Subject’] = “URGENTE! Temperatura: ” + getCPUtemperature()
     # Consigner of your E-Mail
     msg[‘From’] = “Raspberry Pi”
     # recipient of your E-Mail
     msg[‘To’] = “jolimk@gmail.com”
     # Finally send the mail
     server.sendmail(“jolimk@gmail.com”, “jolimk@gmail.com”, msg.as_string())
     print “Everything was working fine! Best regards http://www.quaintproject.wordpress.com

    As you can see it is in Spanish, but there is something wrong going on here. I get the following error:

    pi@retropie:~ $ sudo python notify.py
    File “notify.py”, line 5
    SyntaxError: invalid syntax

    What is wrong here?



    • Hi there,

      I’ve uploaded the script to GitHub’s Gist. The syntax error you’d faced has to do with wrong indention. (WP sometimes messes up the format). In Python it’s necessary to indent the body of a function or a if either for blank spaces or one tab.

      I hope this helps.



    • I dont understand your reply. What can I do in order to use your script?

      Sorry but as I mentioned Im COMPLETYL NEW. Can you give me STEP by STEP instructions on how to do this from SSH or VNC remote connection?

      Thanks a lot


  12. Where is the script?


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s