August 2011
« Jul   Sep »

Mutt : Sending attachments from commandline

We all are familiar with “mail” command in most of the linux/unix platform. We can easily send email from command-line using “mail” command. Also we can use this command to

1. Check the emails to a user box.

[root@conn-web05 ~]# mail
Mail version 8.1 6/6/93.  Type ? for help.
"/var/spool/mail/root": 7 messages 7 unread
>U  1 root@conn-web05.  Fri Jul 29 07:04  31/1154  "Cron <root@finaconn-w"
 U  2 logwatch@fonn-we  Sat Jul 30 07:03 140/5121  "Logwatch for finaconn"
 U  3 root@conn-web05.  Sat Jul 30 07:04  31/1154  "Cron <root@finaconn-w"
 U  4 logwatch@conn-we  Sun Jul 31 07:03 100/3816  "Logwatch f

Type the no. shown on the right side of the line to read that mail. Also you may use d – command to delete the email.
Eg: d200-600
2. How to send a test email

#echo " This is test mail " | mail -s " test mail from dev. server"

You may verify the email delivery by checking the mail log
#tail -f /var/log/maillog” check the last few lines

Now come back to mutt program. It’s a simplest program which having a capable to send out attachment along with the email. This will be useful if you have to send some errors in application and send the error in detailed to the dev. team using a script.

3. Sending email using mutt with attachment

#echo " This is test mail with an attachment" |  mutt -s " Test mail from web-05 " -a /root/anaconda-ks.cfg

1. echo : write the email body
2. -s : subject name
3. -a : attachment file name with full path
4. sender name.

4. Mutt with multiple attachment and email address.

if you have multiple senders and attachments

#echo " This is test mail with an attachment" |  mutt -s " Test mail from web-05 " -a /root/anaconda-ks.cfg  -a /root/mysql_cnf.cfg

6. If you wish to send email as a HTML email.

#mutt -e "set content_type=text/html" -s "Test email"</root/mysample.html

You may also change the from address, reply to address where all the email send out using “mutt” program.

7. Change mutt profile values and from headers.

You may see a file in your home directory “~/.muttrc“. Content will be looks like as follows,

[root@conn-web05 ~]# cat ~/.muttrc
# Mutt sender profile: default
# location cd ~
# Signature file
set signature='~/.signature'
# Customized headers
unmy_hdr *                      # remove all extra headers first.
my_hdr From: Web-05 Exception checker <>
my_hdr Reply-To: root <>
[root@conn-web05 ~]#

8. Send a test mail from a file content

mutt -s "my story" liju@serveridol < /root/mystory.txt

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>