Skip to content

Instantly share code, notes, and snippets.

Last active November 23, 2023 10:41
  • Star 51 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save chandraratnam/f00ab7d4a5298830f692021964fdb99f to your computer and use it in GitHub Desktop.
Mutt + isync mbsync + gmail + multiple accounts.

Mutt + isync multiple accounts Unfinished

This is the setup that I use for mutt, I have two google domain account (read as gmail) and an institution where I work and study account. This means I have two gmail accounts and one outlook 365 account that i want to sync and read via mutt.

I want to store all my email locally as I travel a lot and will be in countries without easy internet access. For this I use mbsync (iSync). As it can handle multiple account types easily and efficently.

The setup works this way

[Remote Mail Servers] <= mbsync => [Local Mail Folders] Mutt (to read mail) xxxx (to send mail)

This setup will create a mutt instance with multiple gmail mailboxes sorted nicely into different folders, easy to browse in just one keypress.

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


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

This guide will use iSync (aka mbsync) to sync mail via IMAP, and mutt to do the rest. If you want just mutt, see this guide. If you want mbsync + mutt + msmtp, follow this guide, delete mutt's SMTP settings, and tack on smtp in another guide.


  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.


Create Both
Expunge Both
SyncState *

# IMAPAccount personal
# ...

IMAPAccount work
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"


set smtp_authenticators = "login"
set ssl_force_tls = yes

folder-hook 'work' 'source ~/.mutt/work'
# folder-hook 'personal'
macro index 1 "<change-folder> =../work/inbox/<enter>"
# macro index 2 
macro index G "!mbsync -a^M" "Update through mbsync"
set move = no

source ~/.mutt/work


set smtp_url = "smtp://"
set smtp_pass = 

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

set from = ""
set realname = "First Last"


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


Here are tweaks I find useful.


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

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

# Don't ask to confirm deletions
set delete

# Don't move read mail to All Mail
set move = no

# Don't show help bar
set help = no

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

# Read top-down mail instead of bottom-up
set sort = reverse-threads

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

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


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

Read html mail

Mutt reads all mail as plain text by default. Use a terminal web browser to render html mail. lynx is our choice.


auto_view text/html


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


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

Copy link

@chandraratnam This is amazing. Thanks, coming from a mbsync newbie!

Copy link

Thanks, now I know that mbsync supports global defaults (for Create, Expunge and SyncState at least)

Copy link

For future reference, Google has permanently disabled the "Allow less secure apps" toggle.

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