how to send a mail with a message in unix script how to send a mail with a message in unix script unix unix

how to send a mail with a message in unix script


echo 'Message body goes here' | mail -s 'subject line goes here' email@provider.com


Try this on the command line or inside a script:

echo "This is the message." | mailx -s "Subject" abc@def.com

You can use pre-defined messages from files:

cat message.txt | mailx -s "Subject" abc@def.com


Alternatively to mailx (mentioned in the other answers) you can also use sendmail:

cat <<EOF | sendmail -tTo: recipients-mailaddressFrom: your-mailaddressSubject: the-subjectmailtextblabla.EOF

Perhaps you need to add the full path to sendmail if it's not in your path. E.g. /usr/sbin/sendmail or /usr/lib/sendmail.

Update:
See also this question