Linux 08172010

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Easy Gmail reading with mutt

By Vincent Danen
If you're like me, you prefer command line tools over GUI tools, and for email you prefer
plaintext over HTML format. You can have the best of both worlds by using Gmail on the
command line with a tool like mutt, although it does take a bit of tweaking. If you prefer to keep
a copy of your mail locally, you can use POP3 (via fetchmail and procmail) or something like
OfflineIMAP to suck mail down and keep a local copy, syncing the mail back and forth.
With mutt, however, because later versions support IMAP and SMTP directly, you are able to
work with your Gmail or Google Apps account using nothing more than mutt itself: no
fetchmail, no procmail, no OfflineIMAP. All of these tools are great, but Gmail has pretty decent
filtering and the advantages of using the web UI when at a computer not your own might make
you prefer IMAP to sucking everything down via POP3 anyway.
Mutt is extremely straightforward when used with Gmail.
First, you need to create a ~/.muttrc with the following contents. These are really the bare-bones
commands you need for mutt to work with Gmail (customize to suit passwords and email
address):
# A basic .muttrc for use with Gmail

# Change the following six lines to match your Gmail account details
set imap_user = "[user]@gmail.com"
set imap_pass = "[password]"
set smtp_url = "smtp://[user]@[email protected]:587/"
set smtp_pass = "[password]"
set from = "[user]@gmail.com"
set realname = "[User Name]"

# Change the following line to a different editor you prefer.


set editor = "vim"

# Basic config, you can leave this as is


set folder = "imaps://imap.gmail.com:993"
set spoolfile = "+INBOX"
set imap_check_subscribed
set hostname = gmail.com
set mail_check = 120
set timeout = 300
set imap_keepalive = 300
set postponed = "+[Gmail]/Drafts"
set record = "+[Gmail]/Sent Mail"
set header_cache=~/.mutt/cache/headers
set message_cachedir=~/.mutt/cache/bodies
set certificate_file=~/.mutt/certificates
set move = no
set include
set sort = 'threads'
set auto_tag = yes
hdr_order Date From To Cc
auto_view text/html
bind editor <Tab> complete-query
bind editor ^T complete
bind editor <space> noop

# Gmail-style keyboard shortcuts


macro index,pager y "<enter-command>unset trash\n <delete-message>" "Gmail archive
message"
macro index,pager d "<enter-command>set
trash=\"imaps://imap.googlemail.com/[Gmail]/Bin\"\n <delete-message>" "Gmail delete
message"
macro index,pager gl "<change-folder>"
macro index,pager gi "<change-folder>=INBOX<enter>" "Go to inbox"
macro index,pager ga "<change-folder>=[Gmail]/All Mail<enter>" "Go to all mail"
macro index,pager gs "<change-folder>=[Gmail]/Starred<enter>" "Go to starred
messages"
macro index,pager gd "<change-folder>=[Gmail]/Drafts<enter>" "Go to drafts"
macro index,pager gt "<change-folder>=[Gmail]/Sent Mail<enter>" "Go to sent mail"
Next, you need to create the directories that mutt will need to store cache information, and also
create the mailcap file in order to view HTML messages and attachments:
$ mkdir -p ~/.mutt/cache/{headers,bodies}
$ echo "text/html; /usr/bin/elinks -force-html %s" >~/.mailcap
Change the path to the preferred CLI HTML browser of your choice: elinks is a great browser;
lynx is good also. You can also add other entries to your mailcap if you prefer; such as launching
OpenOffice.org to view Word files (application/msword) or Evince for PDF files
(application/pdf).
After this, you can start mutt and have immediate access to your Gmail or Google Apps account.
You will be asked to save the certificate information; if you select Always Allow, you won't be
prompted for it again.
This configuration is obviously quite sparse, and there are many tutorials online on how to
spruce up mutt with colors and other features. This is pretty much the bare minimum to get mutt
to work with Gmail; you can send mail and read mail via IMAP, which allows you to get access
to your mail account from anywhere that you can ssh into. The keybindings noted also mimic
some of those keyboard shortcuts used in the web UI. For the paranoid, if you omit the
passwords in the configuration file, mutt will ask you each time you start it up.

You might also like