Jump to content

email-alert for special case: ssmtp / mailutils


Recommended Posts

Posted

Hello dear all, 

 

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: CPU, RAM and disk monitoring using python - see the snippet here: https://www.raspberrypi.org/forums/viewtopic.php?f=32&t=22180

 



import os

# Return CPU temperature as a character string                                     
def getCPUtemperature():
    res = os.popen('vcgencmd measure_temp').readline()
    return(res.replace("temp=","").replace("'C\n",""))

# 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(line.split()[1:4])

# 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:
            return(line.split()[1:5])


what would you suggest - which method is appropiate here!?! 

 

look forward to hear from you 

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines