At job usually I need to create scripts to send mail with logs for example while creating a backup. After looking for some email clients I found Mutt that looked really easy to use and to install. First of all you should now that Mutt it’s a Mail User Agent (MUA) it means you should have already one Mail transfer agent (MTA) installed correctly (To let Mutt use the sendmail command). So there we go…, first we install like usually:

$ sudo apt-get install mutt

The most configuration changes that we would make is to change the default mail to show while sending the mails, as by default it will show the name of our server. This can be edit in the file /etc/mutt/Muttrc:

$ sudo nano /etc/mutt/Muttrc

And we add the following lines:

set realname="Username to show"
set from="username@host"
set use_from=yes

If you want to use this service with different users in the same server, you should create a copy of the configuration file for each user as following:

$ cp /etc/mutt/Muttrc ~/.muttrc

We’re ready to send our first test:

mutt -s "Test mail" -a /srv/test.tgz < /tmp/mailmessage.txt

If everything works good we can start to use it into our bash scripts for monitoring tasks such as backups. Here a small piece of script that I use in my backups:


dateFormat=$(date +"%a, %e/%m/%Y %T")
subject="Backup server ($dateFormat)"

mailcontent=$(cat <<?
	Log - Server backup   

echo "$mailcontent" > /srv/scripts/msg.tmp
echo >> /srv/scripts/msg.tmp

mutt -s "$subject" -a "$attachment" "$destMail" < /srv/scripts/msg.tmp
rm /srv/scripts/msg.tmp