MUTT : Background sending with mSMTP

I am regular mutt user. Here is a good fix to remove waiting while the mutt interacts with the SMTP server to send an email. Previously I used a local mail server, now I am going to use mSMTP which is a SMTP Client just like mutt. We will let the mSMTP do the sending part in the background and will keep reading mails in the mutt, Sounds cool, eh ?

At First, Do Install and Configure mSMTP, don’t worry its a quick one.

Open your .muttrc file, remove smtp_url variable, or comment it.

#set smtp_url = "smtp://vigas@csiom.com@csiom.com"

Append following, change things accordingly.

#sets path to msmtp command
set sendmail="/usr/bin/msmtp"
set envelope_from=yes

#Tells mSMTP to use which block of address to send the email
macro generic "1" ":set from=email@gmail.com"

#Background sending, Hurray !
set sendmail_wait=-1

That’s it guys !

Feel free to share problems, if any. I’ll be back after some sleep.

Installing and Configuring mSMTP

mSMTP is an SMTP client which can be used with various applications and scripts such as Mutt, Php, Python etc

Remember, we will do everything as a sudo user and NOT root.

Install the msmtp and ca-certificates packages.

For Arch
$ sudo pacman -S msmtp ca-certificates
For Debian/Ubuntu
$ sudo apt-get install msmtp ca-certificates
For Fedora/Rhel/CentOS
$ sudo yum install msmtp ca-certificates

Create a new .msmtprc file in your home directory and open it with your favourite editor. VIM neerds alert! (If you don’t know what this means, never mind. Just open the file.)

$ vim ~/.msmtmrc

Copy following text into the .msmtprc file. If you have only one email ID, keep the default section, if you have more then two, add more accordingly.

account default
host smtp.gmail.com
from email@youremailhost.com
auth on
port 587
user email@gmail.com
password MySecret
logfile ~/.msmtp.log
tls on
tls_starttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt


account custom
tls off
tls_starttls off
host smtp.youremailhost.com
from email@youremailhost.com
auth yes 
port 25
user email@youremailhost.com
passwordeval gpg -q --for-your-eyes-only --no-tty -d .mutt/.pass.gpg | awk '/email@youremailhost.com:/ {print $2}'
logfile ~/.msmtp.log

As you can see I have two examples one with simple password and one with encrypted password. You can use password variable for basic use, as used for default account in .msmtprc file. If you don’t want your friends to see your password, who use your computer, and more specifically your user, then you should definately use passwordeval variable. passwordeval variable tells the msmtp to fetch password from an encryped gpg file. More details on Encrypting password in with GnuPG, of course you need to see what you want from that link.

Test your configuration with following command

echo -e "Subject: Test Mail\r\n\r\nThis is a test mail" |msmtp --debug --from=default -t username@gmail.com

It probably won’t work 😉 Change permissions of .msmtprc file then.

chmod 600 .msmtprc

Doesn’t work? Apply common sense!

Still not working? poke me !