This does not work anymore. Instead see a much better and more secure guide at https://gist.github.com/bnagy/8914f712f689cc01c267
This information was compiled from my own experience and from various webpages. Search for mutt gmail and you'll find plenty of references, but some of them are outdated. What I've written below works. I will keep it up-to-date as long as I keep using gmail with mutt.
Don't copypaste blindly. Check paths and other settings both in commands and in config files. I used ~/gmail.crt as certificate path, username@gmail.com as the login/from address, yourpassword as password, /home/myusername as home directory.
1. Get msmtp with OpenSSL support. Get mutt with IMAP support. For Debian I prefer mutt-patched.
2. Get SSL certificate for google:
wget -O ~/gmail.crt http://www.geotrust.com/resources/extended-validation-ssl/certs/Equifax%20Secure%20Certificate%20Authority.crt
3. Verify msmtp will work with this certificate. If this doesn't work, you won't be able to send email.
msmtp -S --host=smtp.gmail.com --tls=on --tls-trust-file=~/gmail.crt --tls-starttls=on --tls-force-sslv3=on --port=587
You should see something like:
SMTP server at smtp.gmail.com (fx-in-f109.1e100.net [74.125.39.109]), port 587: mx.google.com ESMTP o23sm81058faa.9 TLS certificate information: Owner: Common Name: smtp.gmail.com Organization: Google Inc Locality: Mountain View State or Province: California Country: US Issuer: Common Name: Google Internet Authority Organization: Google Inc Country: US Validity: Activation time: Wed Feb 16 06:38:09 2011 Expiration time: Thu Feb 16 06:48:09 2012 Fingerprints: SHA1: DB:A0:2A:07:00:F9:E3:23:7D:07:E7:52:3C:95:9D:E6:7E:12:54:3F MD5: 02:4C:12:F3:37:1F:0C:C1:EB:10:4B:92:F7:F1:E0:DF Capabilities: SIZE 35882577: Maximum message size is 35882577 bytes = 34.22 MiB STARTTLS: Support for TLS encryption via the STARTTLS command AUTH: Supported authentication methods: PLAIN LOGIN
4. Edit your .msmtprc
------xxx------ account gmail host smtp.gmail.com from username@gmail.com auth on tls on tls_starttls on tls_force_sslv3 on tls_trust_file /home/myusername/gmail.crt user username@gmail.com password yourpassword port 587 syslog off logfile /home/myusername/.msmtplog account default: gmail ------xxx------
then
chmod 600 ~/.msmtprc touch ~/.msmtplog && chmod 600 ~/.msmtplog
5. Edit your .muttrc. It should contain at least:
------xxx------ set imap_user="username@gmail.com" set imap_pass="yourpassword" set sendmail="/usr/bin/msmtp" set from="username@gmail.com" set realname="Your Real Name" set use_from="yes" set folder="imaps://imap.gmail.com:993" set ssl_force_tls="yes" set spoolfile="+INBOX" set postponed="+[Gmail]/Drafts" set record="/dev/null" set imap_check_subscribed set timeout="90" set imap_keepalive="300" set mail_check="150" set header_cache=~/.mutt/cache/headers set message_cachedir=~/.mutt/cache/bodies set certificate_file=~/.mutt/certificates ------xxx------
6. Everything should work. If not, check paths, usernames, passwords and search on Google for whatever errors msmtp or mutt throw.