You can test if the sendmail application is installed and working correctly.
1 | $mail -s "Hello world" you@mail.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.
1 2 3 | $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.
1 2 3 | -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.
1 | $echo "body message" | mail -s "test this mail " you@mail.com |
You will find an email on your account named you@mail.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:
1 | $ mail -s "test this mail " you@mail.com < 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:
1 | $free -m | mail -s "free memory output" you@mail.com |
Also, you can create some bash scripts. See below:
1 2 3 4 | #!/bin/bash free -m > output.log df -h >> output.log mail -s "RAM and disk outputs" you@mail.com < output.log |
And such examples could continue.