Send mail bash script

Explains how to write a shell script to send an email from command prompt under Linux / UNIX operating systems.

The mail command can be used under Linux or UNIX bash / ksh / csh shell to send an email. To send a message to one or more people, mail can be invoked with arguments which are the names of people to whom the mail will be sent. You are then expected to type in your message, followed by an ‘control-D’ at the beginning of a line. However, using the following syntax one can send email easily:
mail -s ‘Subject’ [email protected] Sample Shell Script

Here is what you need to put in a shell script:

See also: Sending mail with attachment from command line/shell