I will show you get started with sending mails from the Linux command line. Will also cover sending attachments from the command line. We will begin with the “mail” command.

First we need to test the sendmail application to be installed and working correctly executing the following command:

echo “This is the body of  mail.” | mail -s “Subject” you@youremail.com

Other command line option:

-s subject Specify subject on command line.
-c email-address Mark a copy to this “email-address”, or CC.
-b email-address Send blind carbon copies to list. List should be a comma-separated list of names.

Below are few examples that you can use with the mail command:


mail -s “System Log” you@youremail.com

This command sends a message  with a subject line of “System Log” and the text of the message read from the system logfile /var/log/messages.

df -h | mail -s “Disk Space” you@youremail.com

This command sends a message  with a subject line of “Disk Space” an the text of the output read from command df -h.

free -m | mail -s “Free RAM” you@youremail.com

This command sends a message  with a subject line of “Free RAM” an the text of the output read from command free -m.