Absolutely Tech

[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:

    defaults
    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 username@gmail.com
    password mypass
    from username@gmail.com
    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 username@gmail.com

    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.)
Cheers!

Category: How-To, Ubuntu (Linux)

Tagged: , , , , ,

  • http://twitter.com/xobb xobb
  • http://www.absolutelytech.com Deepak Mittal

    I guess something has changed in newer versions. I had tested that command. Anyways, I’ve updated the post with working command.

  • http://xobb.citylance.biz/2010/11/%d1%88%d0%bb%d0%b5%d0%bc-%d0%bc%d0%b8%d0%bb%d0%be-%d0%b7-%d0%bb%d0%be%d0%ba%d0%b0%d0%bb%d1%85%d0%be%d1%81%d1%82%d0%b0-%d1%87%d0%b5%d1%80%d0%b5%d0%b7-gmail/ Разноє

    Шлем мило з локалхоста через Gmail…

    Прийшла до мене нарешті думка навчити свою робочу конячку відправляти письма мені. Заглушки всякі до sendmail не дуже хочеться писати, а приймати би поштовим клієнтом було би саме кошерніше. Так вот, будемо відправляти всі письма з нашої адреси, яку со…

  • Nobody

    you’re God! there is a mess around about sending emails from command line with all rocket scientists around using monsters to defeat ants. Thanks

  • http://www.absolutelytech.com/2010/07/18/howto-send-emailsusing-mail-function-from-localhost-in-php-through-msmtp-using-gmail-account-on-linux/ [HOWTO] Send emails from localhost in PHP using msmtp (using gmail account) on linux | Absolutely Tech

    [...] install on fedora, redhat, centos.Step by step instructions: First of all, follow this tutorial: Install msmtp on your linux box and configure it to work with Gmail.Msmtp is highly configurable and you can easily configure it to work with any smtp server. If you [...]

  • http://www.okadadesign.no/blog/web-development/sending-email-from-localhost-using-msmtp-with-gmail/ Sending email from localhost using MSMTP with gmail | Okada Design Blog

    [...] goes to this and this [...]

  • http://profiles.google.com/lamouche Glen Winters

    Hello. I just stumbled on this and got it working. Is there a way to encrypt the password so that it’s not shown in plaintext in the config file?

  • http://www.facebook.com/sitthykun Sitthykun Ly-kh

    I got error
    msmtp: cannot log to /var/log/msmtp.log: cannot open: Permission denied
    msmtp: log info was: host=smtp.gmail.com tls=on auth=on user=[email protected] from=default recipients=[email protected] mailsize=40 smtpstatus=250 smtpmsg=’250 2.0.0 OK 1307440481 p5sm25399pbd.12′ exitcode=EX_OK

  • http://www.absolutelytech.com Deepak Mittal

    chmod 0777 /var/log/msmtp.log

  • Rbrunius

    I’m getting the following error to the command line:

    msmtp: /etc/msmtprc: line 1: unknown command defaults

  • http://www.absolutelytech.com Deepak Mittal

    Could you post your msmtprc file. Please remove your username and password before doing so.

  • http://www.charleslabri.com/?p=420 Getting GMAIL notifications via ZABBIX on CENTOS6 – Charles L'Abri Anderson

    [...] Extension  for advanced email notifications How to config centos and php sendmail Configuring msmtp on linux Share this: Posted in Systems – Tagged centos, email, gmail, linux, monitoring, msmtp, [...]

  • manu

    It can not be a good idea to put my gmail password in a file which can be read by everbody!!

  • Guest

    I agree with others that it’s a very bad idea to store the password in plain text. Someone who is competent should provide a tutorial on how to encrypt the password.

Ubuntu 11.04

The next version of Ubuntu is coming soon

Follow me

Sponsors