Client-oriented email setup in Emacs with notmuch
A summary of how I receive, read, filter and send my emails in Emacs using notmuch and friends.
I’ve tried quite a number of email setups but every one of them had their own issues which couldn’t be used reliably, or I simply didn’t like them. After all, using a simple webmail of your email provider can answer most of your needs.
As an avid user of mutt, the single fact that I could not read RTL texts properly in it was a huge drawback for me. And it’s not even a mutt problem; handling RTL texts in terminal is a complete mess, which is really hard to get it completely right.
So as I thought all terminal-based email clients are out of question, Mozilla Thunderbird seemed to be the most logical answer. Don’t get me wrong, Thunderbird is a great program since it’s easy to set up, and you can do pretty much everything you need. But the need of always allocating 400 megabytes of your sweet memory only to emails seems wrong to me.
And finally, when I took a look at email clients in Emacs, I knew that’s it! I could use efficient email clients while having Emacs’s amazing BIDI text support. Frankly, I still would’ve used notmuch over mutt if there was not an RTL support need.
- Notmuch uses tags over maildirs. An email can have multiple relevant tags. I heard Gmail can also be used in a tag-based system, so it might be similar to that.
- Notmuch is very fast and efficient. Even if you receive 12000 messages per month or have on the order of millions of messages that you've been saving for decades. Regardless, Notmuch will be able to quickly search all of it.
- Notmuch has a great library interface, powerful command-line tools and extensive documentation making it very easy to script things out.
Enough of rants, let’s get down to how things work. While notmuch-emacs is just a frontend to manage emails, still tons of other tools are needed to make it work.
First off, imapnotify is used to make a socket to email server and trigger a script (in this case fetching) whenever a new email is received. Some may use cronjobs instead but imapnotify seems a better solution to me.
Then, dunst is triggered in order to get a desktop notification on each new email. There are other notification servers available but dunst was my choice since I use it elsewhere.
Here’s the cool part. getmail is then triggered to fetch emails and delete on mail server after retrieval. I don’t store mails on mail servers. One might think this limits reading emails on different devices, but for me it is actually not. I still can get notification, read and send emails with my phone but whenever I fetch them to my desktop, it’s no longer in different devices. By doing this, the storage limit on mail servers becomes obscure.
However, you don’t have to do this. mbsync or offlineimap can be used to sync between server maildirs and notmuch maildirs. You can even use lieer to do two-way tag synchronization between notmuch and Gmail.
Then, fetched emails are sent to notmuch to index and afew to do initial tagging. As notmuch supports tagging on emails, afew is used to tag new emails for different things. For example, you can tag emails from your family both as personal and family. Or add some spam filters. Afew also have built-in support for mailing lists meaning emails belonging to a specific mailing list will be tagged as such.
Finally, you can open notmuch in Emacs and enjoy reading your emails. The nice thing is that Emacs does not need to be open all the time (like thunderbird) in order for emails to be received.
Also msmtp needs to be configured in order to send emails. Msmtp, as all other programs I used here, support multiple accounts.
How to do all that?
Actually installing and maintaining your configuration for all these pieces of software only to do emails is hard and time-consuming. But if you (like me) use NixOS or nix itself, home-manager has support for all of them.
As everything else in NixOS, it gets a single configuration file written in Nix Language to install and configure different programs.
All my email-related programs are configured in a single and small nix file, but if you’re using another Linux distribution, you can still install and confugure all of them one by one.
Is this setup suitable for you?
Well, you can try!