Send an HTML Email and Attachment With Mutt Mailer in Terminal on Ubuntu 20.04

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.

  1. 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.

  1. Create a new file named something like “mutt-email.sh”
sudo nano mutt-email.sh
  1. 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 <noreply@your-email.com>" \
-c harry@yahoo.com \
-c frank@gmail.com \
josey@icloud.com \
-a "folder1/image1.jpg" < folder1/main.html
  1. When done pasting the modified version of the text above, click “CTRL + X” to save the file and type “Y” and enter to confirm.
  1. 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
  1. To test the new script type the following command into terminal and hit enter.
./mutt-email.sh

2 thoughts on “Send an HTML Email and Attachment With Mutt Mailer in Terminal on Ubuntu 20.04”

    • Ah, yes. Apologies for leaving that part out. What I did was installed postfix and set it up to send emails via relay to and exchange server. You could also configure it to send mail directly, but it’s not as reliable as it could easily and most likely end up getting blocked completely by the recipient or end up in the spam/junk folder.

      To install postfix, run this command: sudo apt update && sudo apt install mailutils

      Here’s a decent guide to use GMAIL as your email relay server: https://restorebin.com/configure-postfix-smtp-relay/

      Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.