Using mutt with gmail

I messed around for a while today trying to get mutt set up to use my Gmail account. Of course, I use the web interface 95% of the time, but sometimes I am on systems that do not have X and/or sendmail/procmail/fetchmail/whatever available. So I wanted a simple, self-contained way to check, and occasionally send, mail from the command line via Gmail. Here’s how mine is set up, in case it’s useful to anyone.

Requirements:

  • mutt with POP3 and SSL support compiled in (for receiving mail)
  • ssmtp (for sending mail)

mutt configuration (in ~/.muttrc)

mail check options

set pop_host=”pops://username:password@pop.gmail.com:995″
set pop_last
unset pop_delete

mail send options

set sendmail=”~/bin/gmailout”

check for new mail on startup

exec fetch-mail

SMTP command (~/bin/gmailout)

This is just a shell script with the connection information for Gmail’s SMTP server. It invokes ssmtp with certain options.

!/bin/sh

/usr/sbin/ssmtp -au “gmail-address” -ap “password” $@

ssmtp configuration (/etc/ssmtp/ssmtp.conf)

mailhub=smtp.gmail.com:465
UseTLS=YES

Just be sure to replace “gmail-address,” “password,” and “username” to fit your information. And the “gmailout” script must be executable. That’s everything. I didn’t find it all in one place, so this is hopefully a working configuration for anyone who wants to do the same thing.