Monthly Archives: June 2010

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.

mutt command line

So today I was working on a script and I needed to send an email via the command line using the mutt client. This how I use mutt through the command line, mutt is a Linux email client… To use mutt you will first have to make sure mutt is installed, depending on your Linux OS the following command will vary but this is how I verified if mutt was installed or not:

yum info mutt


rpm -qa mutt

If you do not have mutt installed you will need to install it using one of the following commands: (you will need to login as root)

# to install mutt on centos or fedora run the following command
yum install mutt
# to install mutt on redhat run the following command
up2date -i mutt

Once mutt is installed you can try the following command, which will send an email using the mutt client:

echo "this is a test" | mutt -s "subject" [email protected]

If you don’t receive your email within a couple of minutesĀ  then you will need to trouble shoot your computers mail server (the workstation/server will be using sendmail). You may need to re-configure the sendmail configuration file.