[HowTo] Configure msmtp to work with gmail on linux

Msmtp is a small but powerful and highly customizable smtp client. You can access gmail smtp using msmtp, which is exactly what I’ll teach in this tutorial.

Step by step instructions:

  1. Install msmtp and ca-certificates for use with SSL:
    sudo apt-get install msmtp ca-certificates
  2. We’ll create and edit the configuration file using Gedit:
    sudo gedit /etc/msmtprc

    Now copy and paste the following code in the text editor:

    tls on
    tls_starttls on
    tls_trust_file /etc/ssl/certs/ca-certificates.crt
    account default
    host smtp.gmail.com
    port 587
    auth on
    user [email protected]
    password mypass
    from [email protected]
    logfile /var/log/msmtp.log

    Needless to say, you have to replace [email protected] with your email and mypass with your password

  3. It should be readable by anyone. However, we’ll still execute the following command to be sure.
    sudo chmod 0644 /etc/msmtprc
  4. Your msmtp configuration is ready. Lets send a test email to yourself to see if everything’s working properly:
    echo -e "Subject: Test Mail\r\n\r\nThis is a test mail" |msmtp --debug --from=default -t [email protected]

    Again replace [email protected] with your own email address and execute it. You should receive an email.

These are the exact commands to be used with Ubuntu.
You can replicate the steps for another distibution by using equivalent commands (For eg; yum install in place of apt-get install for centos, redhat, fedora.)

Leave a comment

Your email address will not be published.