How to send email from the Linux command line
First run a quick test to make sure the “sendmail” application is installed and working correctly. Execute the following command, replacing “firstname.lastname@example.org” with your e-mail address.
# mail -s “Hello ” email@example.com
Hit the return key and you will come to a new line. Enter the text “This is a test from my server”. Follow up the text by hitting the return key again. Then hit the key combination of Control+D to continue. The command prompt will ask you if you want to mark a copy of the mail to any other address, hit Control+D again. Check your mailbox. This command will send out a mail to the email id mentioned with the subject, “Hello”.
# echo “This will go into the body of the mail.”
mail -s “Hello ” firstname.lastname@example.org
And if you want mail to read the content from a file:
#mail -s “Hello ” email@example.com < /home/user/application.log
Some other useful options in the mail command are:
-s subject (The subject of the mail)
-c email-address (Mark a copy to this “email-address”, or CC)
-b email-address (Mark a blind carbon copy to this “email-address”, or BCC)