mutt command line attachment

Yesterday I was working on sending email with mutt from the command line. Today I want to show you how to send an attachment with mutt at the command line. Here is how to send an attachment using mutt from the command line:

# mutt command line attachment, using the switch -a
echo "message here" | mutt -s "subject" [email protected] -a /path-to-attachment

Now I attach my files a little differently. In most of my scripts I create a variable for logging, with mutt I can do two things, output the log directly to the message of the email and attach it as well. To send the contents of a file within the message do the following:

# mutt command line attachment, using the switch -a and cat command
cat /path-to-file.txt | mutt -s "subject" [email protected] -a /path-to-attachment

My code usually looks like the following (where “$LOGFILE” is predefined earlier in my script):

cat $LOGFILE | mutt -s "subject" [email protected] -a $LOGFILE

Your message body no contains the contents of the “path-to-file.txt” and has the file attached, a little redundant but some mobile phones have issues with different file extensions.

Leave a Reply

Your email address will not be published. Required fields are marked *