We are familiar with many graphical platforms to send out emails like Thunderbird, Outlook, Webmail etc. Here I am explaining about a tool used to send emails from the server command line on Linux based systems. It can be used via terminal as well as from bash scripts.
We can install 'mail' tool using the following commands:
On Centos based OS:
yum install mailx -y
On Ubuntu/Debian based:
apt-get install mailx -y
- Once installed, we can send emails using the following commands:
To send a simple mail with some content in the body:
$ mail -s “test mail” [email protected]The -s option is used for mentioning the subject of the email followed by email address in which we need to send the email. After executing the above command, we need to enter the body content and once done, press CTRL + D to exit and send the mail.
- Sending emails to multiple recipients:
$ mail -s “test mail” [email protected],[email protected],[email protected]
- Sending an email with an attachment:
$ mail -s “File attached” [email protected] -A names.txt