Skip to content

Instantly share code, notes, and snippets.

@chrismytton
Created October 29, 2012 20:46
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save chrismytton/3976435 to your computer and use it in GitHub Desktop.
Save chrismytton/3976435 to your computer and use it in GitHub Desktop.
Mutt Gmail config with OS X keychain

Mutt/Gmail/OS X Keychain

Create a new keychain item, enter the Keychain Item Name as mutt, the Account Name as your gmail email address and then enter your password, then add the keychain item.

2-step auth

If you're using Google 2-step auth, you'll need to generate an Application-specific password from your Google Account settings and enter that as the password.

Environment variables

In your ~/.bashrc or ~/.zshrc export the following environment variables, the MUTT_EMAIL_ADDRESS must match what you entered in Account Name for the keychain item.

export MUTT_EMAIL_ADDRESS="username@gmail.com"
export MUTT_REALNAME="John Smith"
export MUTT_SMTP_URL="smtp://username@smtp.gmail.com:587/"

# If you're using google apps put your full email address in the smtp url
# export MUTT_SMTP_URL="smtp://username@domain.com@smtp.gmail.com:587/"

Mutt

Create the ~/.mutt directory and the necessary subdirectories.

$ mkdir -p ~/.mutt/cache

Then place the muttrc file below at ~/.mutt/muttrc.

Source the file you just edited, or restart your terminal, then run mutt from the command line.

set imap_user = $MUTT_EMAIL_ADDRESS
set imap_pass = `security find-generic-password -w -s mutt -a "$MUTT_EMAIL_ADDRESS"`
set folder = "imaps://imap.gmail.com:993" # Base IMAP path.
set spoolfile = "+INBOX" # Path to inbox, + is replaced with 'folder'.
set postponed="+[Gmail]/Drafts"
unset record # Gmail's SMTP servers take care of this
set realname = $MUTT_REALNAME
set from = $MUTT_EMAIL_ADDRESS
set smtp_url = $MUTT_SMTP_URL
set smtp_pass = `security find-generic-password -w -s mutt -a "$MUTT_EMAIL_ADDRESS"`
# Store cache data in ~/.mutt/
set header_cache = "~/.mutt/cache/headers"
set message_cachedir = "~/.mutt/cache/bodies"
set certificate_file = "~/.mutt/certificates"
# Sort email by threads and sort those threads by date, newest first.
set sort=threads
set sort_aux = 'reverse-last-date-received'
set timeout = 3
set mail_check = 900
# Try and prevent imap timeouts
set imap_keepalive = 300
# Use gmail IMAP IDLE support.
set imap_idle
set imap_check_subscribed
unset imap_passive
unset imap_peek
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment