Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vinitkumar/4a76dd1973bebd30f5a755ec3147347f to your computer and use it in GitHub Desktop.
Save vinitkumar/4a76dd1973bebd30f5a755ec3147347f to your computer and use it in GitHub Desktop.
Mutt with multiple IMAP (Google Mail) accounts in the cloud. This is how I have my mutt installation set up and configured. I primarily use Google products for my mail these days, so the config here should be just fine for that. The principle shown here holds true for all mail accounts.

Mutt for multiple email accounts

This is an OS X-centric configuration.

My setup and configuration for Gmail/Google Apps

The idea here is to use environment variables, loaded via aliases to mutt, to control which account you're loading. Years ago I had all of my accounts configured to be accessible from a single mutt configuration, but I find the simplicity and symmetry of this configuration to work better for me.

Once your configuration is complete, you run mutt via the aliases defined in mutt.bash below.

Bash configuration

The bash configuration in the Hermes project is the one I now use, but I'll just show you the relevant bits for mutt here.

.bashrc

function source_modules {
  echo -en "Sourcing bash modules in $HOME/.bashrc.d/"
  for f in $HOME/.bashrc.d/*.bash; do
    load_and_handle_errors $f
  done
  echo -e ""
  unset f
}

source_modules

.bashrc.d/mutt.bash

export MAILCONF="$HOME/.mutt"
alias mutt-allolex="MUTT_INSTANCE=allolex mutt"
# make one alias for each account, e.g.
# alias mutt-work="MUTT_INSTANCE=work mutt"

Mutt configuration

I don't use a ~/.muttrc.

Mutt can use environment variables in its config files.

~/.mutt/muttrc

# Aliases (I like to keep mine separate)
set alias_file = $MAILCONF/$MUTT_INSTANCE/aliases
source $MAILCONF/$MUTT_INSTANCE/aliases

# Caches
set header_cache=~/.mutt/$MUTT_INSTANCE/cache/headers
set message_cachedir=~/.mutt/$MUTT_INSTANCE/cache/bodies
set certificate_file=~/.mutt/$MUTT_INSTANCE/certificates

set spoolfile = "+INBOX"

# Source the correct instance muttrc last
source $MAILCONF/$MUTT_INSTANCE/muttrc

Listing of ~/.mutt/allolex/

cache/
aliases
certificates
muttrc

Put passwords in the OS X Keychain

enter password into the keychain

~/.mutt/allolex/muttrc

This is the configuration specific to your mail account. The password is stored in your Keychain and loaded into config when mutt starts.

set imap_user = "[email protected]"
set imap_pass = `keychain_password example_gmail_service`
set smtp_url = "smtp://[email protected]@smtp.gmail.com:587/"
set smtp_pass = `keychain_password example_gmail_service`
set from = "[email protected]"
set realname = "Your Name"

set folder = "imaps://imap.gmail.com:993"
set spoolfile = "+INBOX"
set imap_check_subscribed
set hostname = example.com
set postponed = "+[GMail]/Drafts"
set record = "+[GMail]/Sent Mail"
#!/bin/bash
KEYCHAIN="${HOME}/Library/Keychains/login.keychain"
# -gs to search by Service field
# -ga to search by Account field
security find-generic-password -gs "$1" $KEYCHAIN 2>&1 | grep password | cut -d '"' -f 2
#!/bin/bash
# Usage in muttrc:
# set query_command='mutt_contacts'
contacts -Sf '%e %n %c' $1 | grep '@'

OS X 10.8 Mutt Revamp Notes

Overall integration as in Hermes?

  • Integrated with OS X.
  • Completely remote via IMAP, i.e. mail not stored locally.
  • Google Apps-centric, but not pathologically so.

Keep passwords in keychain

The security command is built into OS X

security find-internet-password -ga 'allolex imap' 2>&1 | grep password | cut -d '"' -f 2

This can be implemented as a script.

Contacts lookup

brew install contacts

The space below is a tab character (^v^i in console)

contacts -Sf "%e	%n	%c"

set query_command = "contacts -Sf '%e	%n	%c'"

This should also be a script.

Labels / tags (not tags in the mutt sense)

http://blitiri.com.ar/p/other/mutt-labels/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment