How to send e mail from bash

You can send an email from a Bash script using the mail command or sendmail command. Here are some examples:

Using the mail command:

echo "Subject: My email subject" | mail -s "My email subject" [email protected]

This will send an email with the subject "My email subject" to the recipient at [email protected]. The -s option specifies the subject of the email.

Using the sendmail command:

sendmail -v [email protected] << EOF
Subject: My email subject
This is the body of the email
EOF

This will send an email with the subject "My email subject" and body "This is the body of the email" to the recipient at [email protected]. The -v option enables verbose mode, which shows the email being sent.

Using the mail command with a file:

echo "Subject: My email subject" > email.txt
echo "This is the body of the email" >> email.txt
mail -s "My email subject" [email protected] < email.txt

This will create a file called email.txt with the subject and body of the email, and then send the email using the mail command.

Using the mutt command:

mutt -s "My email subject" [email protected] << EOF
This is the body of the email
EOF

This will send an email with the subject "My email subject" and body "This is the body of the email" to the recipient at [email protected]. The mutt command is a more advanced email client that allows you to compose and send emails.

Using the ssmtp command:

ssmtp -v [email protected] << EOF
Subject: My email subject
This is the body of the email
EOF

This will send an email with the subject "My email subject" and body "This is the body of the email" to the recipient at [email protected]. The ssmtp command is a simple SMTP client that allows you to send emails.

Note: The mail command is not available on all systems, and the sendmail command may not be installed by default. You may need to install additional packages or configure your system to use these commands.