granth green sumo

turkey sandwiches!

️ :sunny: :bike: Photo Photo Photo Photo :sparkles:️‍:rainbow:️‍⚧️:sparkles:

Mutt With Imap and Ssl on Os X 23 November 2006

os10, mail, mutt, imap, ssl


Why use Mutt instead of a pretty graphical mail client? Because it still sucks less than anything else I’ve tried.

Mutt is incredibly configurable, which of course means it takes a long time to set up.


Install MacPorts if you don’t have it.

$ sudo port install mutt-devel +headercache +imap +ssl
$ sudo port install msmtp mailtomutt lbdb urlview w3m

configure Mutt

Add the following to ~/.muttrc. Use your own email address and mail server, obvs.

set query_command="lbdbq %s"  # little brother talks to address book
set text_flowed  # use format=flowed
unset wait_key   # return immediately from external programs
set encode_from  # use quoted-printable for From at the start of a line
unset metoo      # remove me from CC
set edit_headers
set autoedit
set read_inc=100

# imap
set imap_idle
set imap_user=grant
set imap_pass=`security find-internet-password -g -r pami -s 2>&1 >/dev/null | cut -d\" -f2`
set folder=imaps://
set spoolfile=imaps://
unset record         # no sent-mail folder
fcc-hook !(~l|~p) !  # save non-list, non-to-me messages to the inbox
set header_cache="~/.mutt/cache/headers"
set message_cachedir="~/.mutt/cache/bodies"
set certificate_file=~/.mutt/certificates
set ssl_force_tls
set mail_check=300

# smtp
set use_envelope_from
set sendmail="/opt/local/bin/msmtp"
set from="Grant Hollingworth <>"
set sendmail_wait=-1  # send in background

# 'mailboxes' has to be after 'set folder' for the '+' to work`
# e.g., mailboxes ! +debian-security-announce


Mutt will cache the headers of the mail in each folder you look at, as well as the bodies of all the mail you’ve read.

mkdir -p ~/.mutt/cache/{bodies,headers}

This stuff adds up, though, and Mutt doesn’t delete old headers and bodies. Make a cron entry to delete cache files more than a week old. Run crontab -e and add the following line:

@hourly find ~/.mutt/cache -mtime +7 -mindepth 2 -delete


Mutt doesn’t have SMTP support built in. Instead, it expects a sendmail-style command to be available. You can use Postfix, which comes with OS X, but I prefer to send the mail using, my mail server. msmtp acts like sendmail and sends mail by SMTP over SSL.

Create ~/.msmtprc with the following, adjusted for your own account:

account default
auth on
user grant
password SEKRIT
tls on
tls_trust_file /Users/grant/.mutt/certificate-authority
tls_starttls off
domain has an SSL certificate, but it’s signed by our own certificate authority. To tell msmtp I trust it, I downloaded the authority certificate.

curl > ~/.mutt/certificate-authority

The domain setting on the last line of .msmtprc is a bit of a kluge. By default, msmtp tells the mail server its name is ‘localhost’. rejects potential spam by denying external mail claiming to be local. I used the domain to work around this.

address book

The Little Brother’s Database (lbdb) can search Apple’s Address Book for email addresses. It also knows how to read Mutt’s alias file, Pine’s address book LDAP directories, and more.

Make ~/.lbdbrc:

MODULES_PATH="$HOME/.lbdb /opt/local/lib/lbdb"
METHODS="m_muttalias m_osx_addressbook"

If you want to search for names with accented characters, you need to make your own version of the m_osx_addressbook script.

mkdir ~/.lbdb


#! /bin/bash -posix
# -*-sh-*-
#     Copyright (C) 2003  Brendan Cully <>
#     Copyright (C) 2005  Roland Rosenfeld <>
#     This program is free software; you can redistribute it and/or modify
#     it under the terms of the GNU General Public License as published by
#     the Free Software Foundation; either version 2 of the License, or
#     (at your option) any later version.
#     This program is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     GNU General Public License for more details.
#     You should have received a copy of the GNU General Public License
#     along with this program; if not, write to the Free Software
#     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.


  $libdir/ABQuery `echo "$@" | iconv -f 'utf-8' -t 'macroman'` | grep -ia "$@"

Copying links and pasting them into your browser gets old after a while. You can’t just click on links in Mutt as in a graphical mail client. The next best thing is urlview, which you can run with ⌃B.


COMMAND open %s

urlview will use open(1) for all links. open will use your default browser.

A lot of mailing lists have headers with URLs in them, which I don’t want to see in the list of links. I made a wrapper to chop them out.


# throw away mail headers to avoid list URLs
ruby -e 'gets until /^\n$/; print while gets' $@ | /opt/local/bin/urlview

For this to work, $HOME/bin should be before /opt/local/bin in $PATH.

viewing HTML mail and images

curl > ~/bin/view_attachment
chmod +x ~/bin/view_attachment


text/html; view_attachment %s html; needsterminal
text/html; w3m -dump -T %t; copiousoutput
image/*; view_attachment %s


alternative_order text/plain *
auto_view text/html

With this setup, Mutt will show the text/plain section of a MIME message with both plain text and HTML. If the message is HTML-only, it will convert it to plain text with w3m. To view HTML in your browser, hit v for the attachment menu, select the attachment, and hit enter.

use UTF-8 uses UTF-8 encoding of text by default, but not all your programs will know that.

add to ~/.profile (or ~/.MacOSX/environment.plist):

export LC_CTYPE=en_US.UTF-8

add to ~/.inputrc:

set input-meta on
set output-meta on
set convert-meta off

Finally, in Terminal’s “Window Settings”, turn off the wide glyphs options under “Display”.

use TextMate to write your mail

Buy TextMate if you haven’t already. It’s really good.

in ~/.muttrc:

set editor="mate -w"

To look up addresses, use the Find Email Address in Address Book command, written by Brett Terpstra and me.

Download and double click it to install. Type part of a name in TextMate and hit ⌃⇧⌘A.

MailtoMutt is a simple program that runs Mutt when you click on a mailto URL. It leaves a Terminal window and itself running after you send the message. Ugly, but it’s better than nothing.

Configure MailtoMutt as the default app for mailto links using RCDefaultApp.

previously: Fixed Pitchfork Feeds