email-alert for special case: ssmtp / mailutils

Recommended Posts


Hello and good day, 


greetings - pretty new to RaspBerry-Pi  and i hpe that this is the correct place here on this board. 

well - since we talk bout linux here in this subforum - i guess that i can give it a try here





I want to make some experience with linux and my rasperry-Pi. 


Well - on the Raspberry Pi, (alert-) messages and notifications are a great option: These messages help in any case of automation:
The ways and methods being sent are various: These messages can use a broad variety on communication channels (e.g. e-mails, SMSs and i love MQTT).  A bunch of APIs are at hand that help to collect data from sensors can be the source for alert emails. With the Raspberry Pi and the the setting of terminal commands. The alert-messages also are able to be configured to be sent by Cron-job.

Sometimes using email, is called ugly it's insecure while parsing it is horrible, triggering on a message arriving is difficult? 
Sometimes much more apropiate is to send small message payloads from one computer to another like MQTT.


the event and use-case:  


i want to send an email when the space on my Raspberry Pi  smd-card is on the way to get low. On a sidenote i would like to delete old files when disk space is very full.

well this could be a great use-case for testing e-mail-alerts: 


- sending an email would be easy in python; 
- the jobs the program needs to do is to check for disk space and delete the oldest files in python also. 


Well to do this job - i guess that We can use ssmtp and mailutils to send out emails. but i have heard that ssmtp is depreciated and outdated:

With mailutils in python i am able to use os.system() orsubprocess().


Here i found a little  snippet that seems to help me: a post taken from a thread here CPU, RAM and disk monitoring using python


import os

# Return CPU temperature as a character string                                     
def getCPUtemperature():
    res = os.popen('vcgencmd measure_temp').readline()

# Return RAM information (unit=kb) in a list                                       
# Index 0: total RAM                                                               
# Index 1: used RAM                                                                 
# Index 2: free RAM                                                                 
def getRAMinfo():
    p = os.popen('free')
    i = 0
    while 1:
        i = i + 1
        line = p.readline()
        if i==2:

# Return % of CPU used by user as a character string                               
def getCPUuse():
    return(str(os.popen("top -n1 | awk '/Cpu\(s\):/ {print $2}'").readline().strip(\

# Return information about disk space as a list (unit included)                     
# Index 0: total disk space                                                         
# Index 1: used disk space                                                         
# Index 2: remaining disk space                                                     
# Index 3: percentage of disk used                                                 
def getDiskSpace():
    p = os.popen("df -h /")
    i = 0
    while 1:
        i = i +1
        line = p.readline()
        if i==2:

Well  the question is should i take ssmpt or msmtp - which seems to be te newer version for the leightweight SMTP-Protocoll ? 

Any and all help is greatly appreciated 

Edited by spin_up
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.