How to send a mail from unix shell script

To send a mail from a Unix shell script, you can use the mail command or sendmail command. Here are some examples:

Using the mail command:

mail -s "Subject" [email protected] << EOF
Body of the email
EOF

This will send an email to [email protected] with the subject "Subject" and the body "Body of the email".

Using the sendmail command:

sendmail -v [email protected] << EOF
Subject: Subject
Body of the email
EOF

This will also send an email to [email protected] with the subject "Subject" and the body "Body of the email".

Using the mail command with a file:

mail -s "Subject" [email protected] < mailbody.txt

This will send an email to [email protected] with the subject "Subject" and the body contents of the file mailbody.txt.

Using the sendmail command with a file:

sendmail -v [email protected] < mailbody.txt

This will also send an email to [email protected] with the subject and body contents of the file mailbody.txt.

Using a mail client like mutt:

mutt -s "Subject" [email protected] < mailbody.txt

This will send an email to [email protected] with the subject "Subject" and the body contents of the file mailbody.txt.

Using a mail client like msmtp:

msmtp -v [email protected] << EOF
Subject: Subject
Body of the email
EOF

This will send an email to [email protected] with the subject "Subject" and the body "Body of the email".

Make sure to replace [email protected] with the actual email address you want to send the mail to, and mailbody.txt with the actual file name and path of the file containing the email body.

Also, note that the mail and sendmail commands may not work if your system has a mail client configured, as they may conflict with each other. In that case, you may need to use a different mail client like mutt or msmtp.