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
auth on
port 587
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
auth yes 
port 25
passwordeval gpg -q --for-your-eyes-only --no-tty -d .mutt/.pass.gpg | awk '/ {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

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 !

7 Replies to “Installing and Configuring mSMTP”

  1. Hi, I am running a RaspberryPi B model with a clean install and all of the updates. I have followed everything from above and checked it twice, but I get the same error each time I run the mailx function.

    After I use Ctrl+D to send the email, I get the following:

    /usr/lib/sendmail:no such file or directory
    “root/” 11/258
    . . . message not sent.

    Any ideas?

  2. Hey Chris, you do not seem to use mSMTP for sending.
    Try this, (change params accordingly)
    $ echo -e “Subject: Test MailrnrnThis is a test mail” |msmtp –debug –from=default -t

    If you intend to use sendmail only, then probably you need to install sendmail with

    sudo apt-get install sendmail

    Let me know if I could be of any more help.

  3. Hi Vigas,
    Nice article. One quick question, in the .msmtprc file you wrote which I guess is the smtp server for gmail based email accounts. But I have in my peculiar case is a Microsoft Exchange 2007 server account. So what do I need to put in said field? Internet search wasn’t much helpful.

Leave a Reply