email notification from a script
I have a Digital Ocean VPS box where several scripts are running. Some of them run for a day. I would like to get an email notification when a particular script starts / ends, or when something happens.
In short: how to send an email from the command line?
First, do the necessary configuration to be able to send emails from the command line (more details here).
Sending email without a body:
mailx -s "subject" < /dev/null "firstname.lastname@example.org" 2>/dev/null
Sending email with a body:
echo 'this is the body of the email' | mailx -s "subject" "email@example.com" 2>/dev/null
I also made a Python wrapper for it that you can find here.