You can test if the sendmail application is installed and working correctly.
$mail -s "Hello world" email@example.com
If you go on and see the message with “Hello world” then is working.
The mail command allows you to send emails from Linux terminals and to make some tricks for you.
$Usage: mail -eiIUdEFntBDNHRV~ -T FILE -u USER -h hops -r address -s SUBJECT -a FILE -q FILE -f FILE -A ACCOUNT
-b USERS -c USERS -S OPTION users
Let’s see some of these options.
-s subject of the mail
-c email-address = CC
-b email-address = BCC
Let’s see how you can put some text in body message of the email.
$echo "body message" | mail -s "test this mail " firstname.lastname@example.org
You will find an email on your account named email@example.com.
This message will have the title: test this mail and a body: body message.
If you want to mail to read the content from a file, then:
$ mail -s "test this mail " firstname.lastname@example.org < test.log
This will send one message with the content of test.log.
Why do we need to send emails from the terminal?
The first reason is the need to send logos and outputs of some commands.
Here is an edifying example:
$free -m | mail -s "free memory output" email@example.com
Also, you can create some bash scripts. See below:
free -m > output.log
df -h >> output.log
mail -s "RAM and disk outputs" firstname.lastname@example.org < output.log
And such examples could continue.