Skip to content

Instantly share code, notes, and snippets.

@jkyiv
Created October 24, 2018 13:44
Show Gist options
  • Save jkyiv/814162a4a2ae19c98e0471116213bac2 to your computer and use it in GitHub Desktop.
Save jkyiv/814162a4a2ae19c98e0471116213bac2 to your computer and use it in GitHub Desktop.
Mutt + gmail + isync mbsync + multiple accounts

Mutt + isync multiple accounts

Mutt mail with multiple gmail accounts synced by mbsync, easy to browse in just one keypress. iSync (aka mbsync) is modular, handles multiple accounts (Gmail, Yahoo, Outlook) with ease, and syncs much faster than IMAP.

~/
|── .mutt/
|   ├── muttrc
|   ├── work
|   └── work/
└── .mbsyncrc

Alternatives

   Synchronize mail   <->   manipulate mail   ->   send mail
   [    mbsync    ]                                [ msmtp ]
   [     mutt     ]         [     mutt    ]        [ mutt  ]

This guide uses iSync (aka mbsync) to sync mail via IMAP, and mutt to do the rest.

Configure

  1. Install isync and mutt through brew or equivalent.
  2. If on Gmail, enable IMAP.
  3. If on Gmail 2FA, make an App Password.
  4. If on Gmail non-2FA, enable less secure apps.

~/.mbsyncrc

Create Both
Expunge Both
SyncState *

# IMAPAccount personal
# ...

IMAPAccount work
Host imap.gmail.com
User work@gmail.com
Pass 
SSLType IMAPS
AuthMechs LOGIN

IMAPStore work-remote
Account work

MaildirStore work-local
Path ~/.mutt/mailbox/work/
Inbox ~/.mutt/mailbox/work/inbox

Channel work-inbox
Master :work-remote:
Slave :work-local:
Patterns "INBOX"

Channel work-sent
Master :work-remote:"[Gmail]/Sent Mail"
Slave :work-local:sent

Channel work-trash
Master :work-remote:"[Gmail]/Trash"
Slave :work-local:trash

Group work
Channel work-inbox
Channel work-sent
Channel work-trash

# Gmail mailboxes:
# "All Mail"
# "Drafts"
# "Important"
# "Sent Mail"
# "Spam"
# "Starred"
# "Trash"

~/.mutt/muttrc

set smtp_authenticators = "login"
set ssl_force_tls = yes

macro index G "!mbsync -a^M" "Update through mbsync"
set move = no

folder-hook 'work' 'source ~/.mutt/work'
# folder-hook 'personal'
source ~/.mutt/work

~/.mutt/work

set smtp_url = "smtp://work@smtp.gmail.com:587"
set smtp_pass = 

set folder = "~/.mutt/mailbox/work"
set spoolfile = +inbox
set postponed = +drafts
set trash = +trash
set record = ""

set from = "work@gmail.com"
set realname = "First Last"

Go!

Start mutt in a terminal. Press Shift+g to sync, and c ? to change mailboxes.

Tweaks

~/.mutt/muttrc

# Recent mail on top
set sort = reverse-threads

# Dont add a '+' to urls that wrap
unset markers

# Don't ask to confirm deletions
set delete

# Don't wait to switch mailboxes
set sleep_time = 0

# Don't show help bar
set help = no

# Use mousewheel
bind pager <down> next-line
bind pager <up> previous-line

# Simplify UI
set status_format = "%f"
set date_format = "%m%d"
set index_format = "%Z %D %-15.15n %s"

# Change mailboxes with numbers
macro index 1 "<change-folder> =../work/inbox/<enter>"
# macro index 2

# Keep a list of contacts ('aliases')
set alias_file = ~/.mutt/alias
source $alias_file

~/.mutt/work

# Append a signature to mail
set signature = ~/.mutt/work.signature

Read html mail

Use lynx to have mutt render html mail.

~/.mutt/muttrc

auto_view text/html

~/.mailcap

text/html; lynx -dump %s; nametemplate=%s.html; copiousoutput;

Troubleshooting

No issues as of July 2018. Please comment your feedback!

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