In this brief tutorial, you will learn how to quickly and easily create a bash script to send an email with an attachment and html in the body on Ubuntu 20.04 using Mutt mail client from Terminal.
- Install Mutt Mail by entering the following commands in terminal on Ubuntu.
sudo apt update sudo apt install mutt
To continue with the install, type “Y” and hit enter.
- Create a new file named something like “mutt-email.sh”
sudo nano mutt-email.sh
- Copy the text below and modify the subject, email addresses and folder and file paths to suit your needs and paste it into the mutt-email.sh file which you just created.
#!/bin/bash mutt -e "set content_type=text/html" -s "Test Email Subject" \ -e "my_hdr From: Some Person <email@example.com>" \ -c firstname.lastname@example.org \ -c email@example.com \ firstname.lastname@example.org \ -a "folder1/image1.jpg" < folder1/main.html
- When done pasting the modified version of the text above, click “CTRL + X” to save the file and type “Y” and enter to confirm.
- Now, we must make the mutt-email.sh file executable by changing the file properties. Type the command below in terminal and his enter.
sudo chmod +x mutt-email.sh
- To test the new script type the following command into terminal and hit enter.