Emacs mail revisited: Notmuch is amazing!

I followed David’s tutorial on YouTube about mu4e, but I couldn’t get it to work, maybe because of a straight/apt install mismatch or confusion.

I thought I would share my experiences.

To make a long story short, I installed notmuch on my LMDE6 system instead, following several YT tutorials, by Prot and others. Notmuch is a completely different approach to mail than mu4e, mutt and other similar mail clients. It’s like having Gmail inside Emacs, only better, faster and more flexible! There is no concept of mailboxes, everything is a search. You can tag your emails and define and store searches so they work like “mailboxes”, e.g. all mails from a particular person, or all mails with a specific tag.

And it is lightning fast, based on the excellent Xapian database, it returns the search in matters of milliseconds, it’s actually Emacs that creates delay if the search returns many results.

I love being able to do searches from the terminal, which I actually need to do a.t.m. to remove mails completely. I can tag junk mails del in Emacs, but then to actually get rid of them, I do this:

$ notmuch search --files=output tag:del | xargs rm

Those files are subsequently removed from the upstream IMAP server the next time mbsync is run.

I managed to assemble all my mails from various services (gmail, outlook, icloud) plus maildirs I have backup’ed from long gone computers at work. I now have 70.000 emails in one place, and using various searches, I was able to clear out and delete 2000 mails of no interest anymore, in a couple of hours. But I could take a trip down memory lane reading emails from 30 years ago. Using a bit of trickery with the notmuch config file when indexing mail newly copied to ~/Mail (notmuch new command) I could tag my work mails and other categories so I can now find them and search them independently.

As a comment to David’s video, be aware that with Gmail, you only need to syncronize two “folders”: “All Mail” and “Sent Mail”. Notmuch plus your tags and searches will do the same that Gmail does behind the scenes, if that’s what you want. Gmail’s understanding of “Inbox” is merely a label and it doesn’t play nice with IMAP, because syncronizing it will give you duplicates of the files in “All Mail”. I also found that it’s very convenient to avoid the annoying ‘[Gmail]’ directories when using mbsync, it can place the mail in local folders with sensible names, “sent” and “all” in the following configuration:

Channel gmail-all-mail
Far :gmail-remote:"[Gmail]/All Mail"
Near :gmail-local:all

Channel gmail-sent-mail
Far gmail-remote:"[Gmail]/Sent Mail"
Near :gmail-local:sent

I hope this will inspire folks to try this amazing system, and perhaps David to make a video about it.


Thanks, I think that I’ve got the basic notmuch setup working and it is very nice for reading and searching.

I’m still not sure about how everything fits together. I’d appreciate some help on these questions please.

  1. Do I need to call mbsync and then notmuch new to read the latest email?
  2. Deleting email in the maildir and then using mbsync deletes the email in the server?
  3. Nested directories in the web interface is achieved using multiple tags in notmuch?
1 Like

I am also learning, but I’ll attempt to answer your questions.

  1. Yes, but the way to do it is to use a notmuch hook. The one to define is pre-new. I have my hook script placed in ~/.config/notmuch/default/hooks/pre-new and it simply calls mbsync, but it could also manipulate tags, e.g. remove all ‘new’ tags before the import tags the incoming messages with that tag. When you are in the notmuch-hello interface in Emacs, the key “G” executes “notmuch-poll” which again calls “notmuch new”.
  2. It depends on how you have set up mbsync, especially the settings “Create Both”, “Expunge Both” and “SyncState *”. Check the mbsync docs. When I delete messages that have been tagged “del” (you can use any tag, your choice) they are deleted on Gmail.
  3. I don’t quite understand this question, if you are asking if tags are transferred back to the IMAP host the answer is no.

Hope this helps!

Thanks!, I was confused regarding the first point, your answer is very illuminating. I read some articles and people use systemd or a cronjob to run mbsync and notmuch, your approach from within emacs is much better, I will do that.

About the third question: in my email web interface I organize mail in nested directories, I was wondering how to achieve that in notmuch. I found out about the folder search-term, and also some people use tag in the format “category/item”. I will try and see which approach works best for my use case.

1 Like

Good to hear you are finding your way around notmuch ! It is really a framework where you are required to design exactly the UI and content treatment you want, but it takes some time to work it out. I find the notmuch approach to email is orthogonal to every other client I have used, where you are constricted to “mailboxes” and it has suddenly made my enormous store of emails a valuable resource, because I can search and categorize it in countless ways.