Emacs, Notmuch, isync, and msmtp Setup
I’ve been meaning to move my email management to Emacs for the past year and finally made the jump after see Mike Zamansky’s video on this (YouTube). Here are my notes on how I got this all setup and configured.
This is an opinionated setup based on Mac OS X and Fastmail. First, make sure you have Homebrew installed to install the packages needed.
Receiving email
Notmuch requires email to be stored on your local filesystem and one message per file. We’ll be using isync
for this.
$ brew install isync
You’ll need to start out with an initial config which you can copy directly to your home directory.
My .mbsyncrc
file looks like this:
# First section: remote IMAP account
IMAPAccount fastmail
Host imap.fastmail.com
Port 993
User jonathanchu@fastmail.com
# For simplicity, this is how to read the password from another file.
# For better security you should use GPG https://gnupg.org/
PassCmd "cat ~/.mbsync-fastmail"
SSLType IMAPS
SSLVersions TLSv1.2
IMAPStore fastmail-remote
Account fastmail
# This section describes the local storage
MaildirStore fastmail-local
Path ~/Maildir/
Inbox ~/Maildir/INBOX
SubFolders Verbatim
# This section a "channel", a connection between remote and local
Channel fastmail
Master :fastmail-remote:
Slave :fastmail-local:
Patterns *
Expunge None
CopyArrivalDate yes
Sync All
Create Slave
SyncState *
The contents of .mbsync-fastmail
contains my email password, which is probably not the best way to do store a password like this locally so I should fix this in the near future.
Once this is configured and saved in your home directory, you can then run run mbsync
to pull your email down locally:
$ mbsync -a
Note, you’ll have to run this each time to retrieve new mail. I know some folks might elect to have this as a running cron job every x minutes - this can be entirely based on your preference and email workflow.
And finally, we just need to setup a search database for notmuch
to work by running:
$ notmuch new
Viewing and writing email
We’re going to use Notmuch
, specifically in Emacs, to view our mail. First, you need to install Notmuch
on your OS:
$ brew install notmuch
Once notmuch
is installed, run the following command to setup notmuch
. This will create a .notmuch-config
in your home directory.
$ notmuch setup
When you have entered your email information, in your Emacs configuration, you can install notmuch-emacs
by including the following:
(use-package notmuch
:ensure t
:defer t)
Then, you can run m-x notmuch-hello
and you will be greeted with the notmuch
starting screen.
Sending email
Next, we’ll need to send our mail with something, so I chose msmtp
because of how easy it was to configure.
$ brew install msmtp
The contents of my .msmtprc
file looks like this:
defaults
auth on
protocol smtp
tls on
account fastmail
host smtp.fastmail.com
port 465
user jonathanchu@fastmail.com
passwordeval "cat ~/.mbsync-fastmail"
tls_starttls off
from jonathanchu@fastmail.com
account default : fastmail
Add this bit in your Emacs config:
(setq send-mail-function 'sendmail-send-it
sendmail-program "/usr/local/bin/msmtp"
mail-specify-envelope-from t
message-sendmail-envelope-from 'header
mail-envelope-from 'header)
This article will be updated as I refine my email process and work out the bugs, but at this point you should have working email with Notmuch in Emacs!