Mutt is a full-featured text-based Mail User Agent that supports the typical mail formats and protocols while providing comprehensive support for MIME, GPG, and PGP. By its very nature Mutt is a very useful package, and because it is a tool that all server administrators should become familiar with, it is the purpose of this recipe to show you how Mutt can be used to deliver customized reports and messages to a destination of your choice.
Installing and Configuring mutt
1. Install the mutt RPM package if needed.
# yum install -y mutt
2. Review the online documentation:
# man mutt
3. Set your mail distribution server in the system-wide configuration file. Take a backup of the configuration file before making any changes.
# cp -p /etc/Muttrc /etc/Muttrc.ORIG
# vi /etc/Muttrc ### Change the mail handler to have a line reading: smtp_url=smtp://mailserver.thegeekdiary.com
4. Save the file. restart any mutt sessions already active.
Sending e-mail Using mutt Command
Use mutt command in following format to specify subject, message body and attachment to send mail from command line.
# echo "" | mutt -s "subject" -i body.txt -a attachment.txt firstname.lastname@example.org
-s is used to specify subject of mail.
-i is used to specify file containing message body.
-a is used to specify attachment file.
Some other commonly used options with mutt are:
-b is used to add Bcc address.
-c is used to add Cc address.
-e “unmy_hdr from; my_hdr From: email@example.com” – if you want to specify sender’s address (something other than default).
Mutt can also be used in interactive mode. To start it just type “mutt” on command line.
How to Send an eMail in HTML Format Using mutt?
Use the below syntax to use mutt to send HTML mail:
# mutt -e "set content_type=text/html" [firstname.lastname@example.org] -s "This is the subject" < /tmp/email_body.html
/tmp/email_body.html has the html mail body.