Introduction
Like most people these days I have quite a few email addresses,
personal, old personal email, and school. In the past I’ve tried using
Emacs to manage all of these in one place. However, when I added a work
email account into the mix that didn’t have IMAP
enabled
it was finally enough to make me go back to using the web clients.
Recently I started to get the itch to bring the config into my dotfiles, since the biggest pain was setting it all up on a new computer and making it feel fragile.
Guides:
- Notmuch of a mail setup Part 1- mbsync, msmtp and systemd
- http://www.macs.hw.ac.uk/~rs46/posts/2014-01-13-mu4e-email-client.html
- https://youtu.be/obY1um6ehDM
Notmuch config of my dotfiles:
Fetching the Mail
In the past I’ve tried offlineimap but it’s slow when you have to pull down years and years of email. So I first started with mbsync(I’ve used the arch wiki because it explains more than the actual documentation in my opinion).
To get that set up:
and then add a ~/.mbsyncrc
file and configure it according
to one of the above guides or the arch
wiki. I will try to avoid
going over things that I just copied and pasted and they worked, in
order to keep this short.
An issue that I ran into later down the road was that mbsync doesn’t sync just any flag/label/tag back to Gmail. Enter gmailieer. Which was more of a pain to setup.
To install from here
The chicken and the egg problem with gmailieer
is that it
needs notmuch
set up in the .mail
dir. So when
I was setting gmailieer
up, notmuch
was
already up and running for me. We’ll come back to it.
With gmailieer
the important part, is if I check my email
on my phone, another computer, or Emacs, it will update as read,
archived, deleted, and most importantly the tags will be the same on it.
For an added bonus it works for my work account that uses Gsuite since
it uses their API and not IMAP.
Now one key issue I had with gmailieer
and my setup is that
it depends on the python3-notmuch
package, which is in the
Ubuntu repos but not in pypi
. So this makes it necessary to
use a different version of python than Conda 3.6(default in 18.04 but
you can use the python-notmuch
package if you’re on 16.04)
I had to do the following(I use pyenv
to manage different python versions).
We need to initialize the notmuch database.
Here you’ll be prompted with some questions to get your config going. Below is an example of what it’ll look like afterwards
Checking Mail in the Background
Next we need to setup the mail to be ran in the background every so often. This guide has a great setup for it.
And start and enable the timer
The checkmail.service
calls checkmail.sh
The gmi sync
command does a push
followed by a
pull
so the tags from the local overwrite anything that’s
on the remote. So later we’ll write rules to tag the new mail coming
in.
Tagging the Mail
The next step is to tag the mail. For that I use notmuch
I
tried mu
in the past but it works by moving the emails into
various dirs instead of just tagging them and I found it messed with how
the remote emails were treated too often. Gmailieer pulls the tags down
by default. But if we want to tag our mail locally we’ll need to expand
checkmail.sh
. afew is
another option for more elaborate initial tagging, but I didn’t want to
have more dependencies.
So what we’re doing here is first calling notmuch new
which tags everything according to this section of the config. Which
just tags everything with new
and ignores anything with the
Trash
tag.
Deleting Email
Notmuch by default doesn’t tag things with +trash
which
makes gmail move the emails to the trash. Here’s a snippet that does
that. I have this bound to d
.
WIP: Sending Email
WIP: Currently I can only get this to work with my primary email address.
To set this up we’ll need to get started with pass. I suggest you have a look at the Doom Notmuch module if you’re not using Doom to give you an idea of any features you need to setup.
First setup ~/.msmtprc
Then we’ll setup pass
.
And type in the password.
You should be good to go and when in notmuch
hit
C
and the C-c C-c
to send and
C-c C-k
to cancel.