The description reads:
Being able to send emails from command-line from a server is quite
useful when you need to generate emails programatically from shell
scripts or web applications for example.
How the mail command works
For those who are curious about how exactly the mail command delivers the mails to the recipients, here is a little quick explanation.
The mail command invokes the standard sendmail binary (/usr/sbin/sendmail) which in turns connects to the local MTA to send the mail to its destination. The local MTA is a locally running smtp server that accepts mails on port 25.
mail command -> /usr/sbin/sendmail -> local MTA (smtp server) -> recipient MTA (and Inbox)
This means that an smtp server like Postfix should be running on the machine where you intend to use the mail command. If none is running you get the error message "send-mail: Cannot open mail:25".
Open terminal & type following command in terminal.
sudo apt-get install mailutils
sudo apt-get install sendmail
After installing sendmail , you should configure sendmail. It
s little hard. But dont worry after that we can spoof email to anyone.
Type following command on terminal
sudo gedit /etc/mail/sendmail.mc
It will open sendmail.mc file.
For example your last two lines are as follows:
Put this code before those two lines.
Now close that file
Now we will generate configure file from .mc file so type following command in terminal.
sudo bash -c 'cd/etc/mail/ && m4 sendmail.mc >sendmai.cf'
Now everything is complete, try to send mail using terminal
Some examples from the link that I provided:
Use the mail command
Run the command below, to send an email to email@example.com. The
s option specifies the subject of the mail followed by the recipient
$ mail -s "Hello World" firstname.lastname@example.org
- Send mail to a local system user
To send mail to a local system user just use the username in place of the recipient address
$ mail -s "Hello World" username
- Specify the FROM name and address
The "-a" option allows to specify additional header information to attach with the message. It can be used to provide the "FROM" name and address. Here is a quick example
# echo "This is the message body" | mail -s "This is the subject" email@example.com -aFrom:firstname.lastname@example.org
The a option basically adds additional headers. To specify the from name, use the following syntax.
$ echo "This is the body" | mail -s "Subject" -aFrom:Harry\<email@example.com\> firstname.lastname@example.org
Note that we have to escape the less/great arrows since they have special meaning for the shell prompt. When you are issuing the command from within some script, you would omit that.
What is mail?
mail command examples
Install and Configure mail