I’ve been using this email solution for some time now. My muttrc has been called both epic and awesome, so I figured I’d share my setup and how it got that way here.
What is it? A couple of applications working together to offer a simple, clean, usable way of interacting with my gmail account.
This post shares a lot of information with my second mutt post regarding multiple accounts accessed through mutt and offlineimap. If that’s something you’re planning on setting up you can skip this tutorial as it’s a subset of the information there.
Offlineimap syncs a local Maildir at ~/Mail with my gmail IMAP account every 3 minutes. I use mutt to interface with said Maildir, and msmtp to send email from mutt via gmail’s smtp server.
Full config files can be found in my mutt-config repo but I’ll post the important bits here.
Offlineimap
Step one is to setup Offlineimap to keep ~/Mail in sync with our gmail’s IMAP folder. This is a two way sync so anything moved, deleted, or sent from any IMAP-connected interface or our local mutt interface will act exactly the same. This also has the added benefit of storing offline, local copies of all your mails.
First, install Offlineimap and fill in an ~/.offlineimaprc like so:
[general]
# NOTE: cronjob calls the quiet UI with -u
ui = ttyui
accounts = GMail
[Account GMail]
localrepository = Gmail-Local
remoterepository = Gmail-Remote
[Repository Gmail-Local]
type = Maildir
localfolders = ~/Mail/GMail
[Repository Gmail-Remote]
type = Gmail
remoteuser = username@gmail.com
remotepass = gmailpassword
realdelete = no
# "[Gmail]/Some Folder" --> some_folder
nametrans = lambda folder: re.sub('^inbox$', 'INBOX',
re.sub(' +', '_',
re.sub(r'.*/(.*)$', r'\1', folder).lower()))
# vim: ft=cfg tw=0Take note of the nametrans. My line there will change folder names during the sync so IMAP/[Gmail].Archive becomes ~/Mail/archive and similar for all other folders. You can choose not to use this line if you don’t mind the default folder names, but you’ll have to be careful to use the right folder names in your ~/.muttrc.
Offlineimap is kind of buggy for me, if I use its built in refresh mechanism I find it’ll often hang or quit and I’ll be left with an unsynced mailbox. Therefore, I set offlineimap to never refresh and put a [re]start script in a cronjob to take care of it.
For now, you can test by running offlineimap -o.
Once you’re sure things are syncing fine, set up a cron job to run a script called mailrun.sh every 3 minutes:
crontab -e
# then add this:
*/3 * * * * /path/to/mailrun.shThen create that script with these contents:
#!/bin/bash
PID=$(pgrep offlineimap)
# the only time offlineimap has been still running after 3 minutes for
# me is if it's frozen... we'll kill it and resync
[[ -n "$PID" ]] && kill $PID
offlineimap -o -u quiet &>/dev/null &
exit 0And make it executable via chmod +x /path/to/mailrun.sh
You may have to restart cron for these changes to take affect
Msmtp
Now we need a way to send mails via gmail’s smtp server. I like msmtp, you can also use other smtp clients. If you choose to install msmtp, the config file is at ~/.msmtprc and should look like this:
# msmtp config file
account default
host smtp.gmail.com
port 587
protocol smtp
auth on
from user@gmail.com
user user@gmail.com
password XXXXX
tls on
tls_nocertcheckMutt
Now the fun part! I don’t know how many hours I’ve spent in the past year fine tuning my muttrc, but it’ll never be done. Here are the parts required to get this setup working.
# options
set mbox_type = Maildir # mailbox type
set folder = ~/Mail # root folder
set spoolfile = "+INBOX" # inbox
set mbox = "+archive" # [Gmail]/All Mail
set postponed = "+drafts" # [Gmail]/Drafts
unset record # required to prevent duplicates in Sent
set sendmail = /usr/bin/msmtp # use msmtp 'default' account
# mailboxes
mailboxes +INBOX +archive +sent +drafts +spam +trash
# bindings
macro index D "<save-message>+trash<enter>" "move message to the trash"
macro index S "<save-message>+spam<enter>" "mark message as spam"The above should be enough to get a connection and start sending/receiving mail, but here are some other must-have options that make it feel a bit more like gmail:
# main options
set realname = "Real Name" # who am i?
set from = "user@gmail.com" # who am i?
set envelope_from # which from?
set mail_check = 0 # check for mail always
unset move # gmail does that
set delete # don't ask, just do
unset confirmappend # don't ask, just do!
set quit # don't ask, just do!!
unset mark_old # read/new is good enough for me
# index options
set sort = threads # like gmail
set sort_aux = reverse-last-date-received # like gmail
set sort_re # thread based on reply_regexp
# pager
set pager_index_lines = 8 # show 8 messages when in pager
set pager_context = 5 # show five lines when skipping in pager
set pager_stop # don't go to next message automatically
set menu_scroll # scroll in menus
set smart_wrap # don't split words
set tilde # show tildes like in vim
unset markers # no ugly plus signs
# composing mail
set fcc_attach # save attachments with the body
unset mime_forward # forward attachments as part of body
set forward_format = "Fwd: %s" # format for subject when forwarding
set include # include message in replies
set forward_quote # include message in forwards
# headers to show
ignore * # ignore all headers
unignore from: to: cc: date: subject: # show only these
hdr_order from: to: cc: date: subject: # and in this orderI’ve left out quite a few tweaks in the above so that those who are happy with mutt’s very sane defaults aren’t overwhelmed. Keep in mind, man muttrc is a great command for when you’re bored.
That should do it. Hopefully this info will get you going in the right direction. You might notice my various mutt settings are spread across a few different files. These are then sourced in the main ~/.muttrc. You might also find this approach useful, or you can just put everything in one file.
Showing 3 comments:
Please log in to post a comment.