You can send an email in a bash script using mutt command. Here I have explained how you can send an email with an attachment to multiple recipients using a linux shell script.

Here is the format of the script.

echo "<message body>" | mutt -s "<subject>" -a "<optional attachment>" -e "my_hdr From:<from address>" -- <recipients list separated by space>

Below is a sample bash script using the above code format.

subject="Email from bash"
body="This email was sent using a bash script"
from="[email protected]"
to="[email protected] [email protected]"
fileAttachment="/tmp/test.txt"

echo "Sending email..."
echo "$body" | mutt -s "$subject" -a "$fileAttachment" -e "my_hdr From:$from" -- $to
echo "Email sent to: $to"

Additionally you can use following parameters,

  • -c carbon copy (Cc)
  • -b blind carbon copy (Bcc)

You can view the full parameter list in official mutt website.

About the Author

Sadupa Wijeratne

Sadupa Wijeratne is the founder of My Cute Blog. Currently working as a software engineer. Interested about latest technologies and love to learn by experience.

View All Articles