How to send mail from the Linux Command line (or shell script) using the mail command.
echo “This is the body of the email” | mail -s “Email Subject” firstname.lastname@example.org — -f email@example.com
The — -f section is used to plug in a sender address, otherwise the mail will be sent from your root or user account from the actual physical server name – e.g firstname.lastname@example.org
This comes in handy for notification of script execution, for example, jobs in the crontab. Placing this code immediately after the last command in a shell script will ensure relevant person(s) are notified when the script is called.