mu4e

mu4e is an email client for Emacs. It’s based on the mu email indexer/searcher.

It's not information overload. It's filter failure. mu4e's mission is to be a better filter. --Prof. Shirky

mu4e first appeared in mu 0.9.8.

Features

Quickstart

This tutorial assumes you have use a tool such as mbsync or mpop to retrieve your mail into a maildir folder called ~/mail.

Download mu from your package manager, then, from the commandline, run:

mu init --maildir=~/mail --my-address=me@example.com

From Emacs, download Mu4e with M-x package install RET mu4e RET and run it with M-x mu4e.

Press U to update Mu4e’s mail listing, and bu to see all your new mail or j to jump to a maildir folder.

Tips

Context templates

Defining mu4e contexts for multiple email addresses that only differ in the “from” field and maybe signature, while automatically matching their corresponding address using their :match-func (when replying to messages) can quickly get pretty verbose and clunky. To keep it lean and avoid code duplication, one can define a function to build a context based on a template:

  (defun my-make-mu4e-context (name address signature)
    "Return a mu4e context named NAME with :match-func matching
  its ADDRESS in From or CC fields of the parent message. The
  context's `user-mail-address' is set to ADDRESS and its
  `mu4e-compose-signature' to SIGNATURE."
    (lexical-let ((addr-lex address))
      (make-mu4e-context :name name
                         :vars `((user-mail-address . ,address)
                                 (mu4e-compose-signature . ,signature))
                         :match-func
                         (lambda (msg)
                           (when msg
                             (or (mu4e-message-contact-field-matches msg :to addr-lex)
                                 (mu4e-message-contact-field-matches msg :cc addr-lex)))))))

Then, easily define contexts:

    (setq mu4e-contexts
        `( ,(my-make-mu4e-context "main" "me@example.com"
                                  "Emacs is awesome.")
           ,(my-make-mu4e-context "work" "me@work-example.com"
                                  "A very professional signature.")
           ,(my-make-mu4e-context "other" "activist@example.com"
                                  "Plain text mail forever.")))

Integrating with mbsync

I use mu4e with mbsync (and GMail). Since it takes a while, mbsync runs in a cron job every 10 minutes or so, which mostly works (and I don’t want mu4e to wait for a sync). However, sometimes I want to refresh my emails now (“Hey, I just sent you something…”). This code changes the meaning of the prefix argument to “U” so that it re-syncs when given a prefix and doesn’t otherwise.

    (setq mu4e-get-mail-command "mbsync gmail")
    ;; Most of the time, I merely want mu4e to re-index my local maildir (because
    ;; I'm running mbsync as a cron job). However, sometimes I want to fetch mails
    ;; immediately. Do this by changing the meaning of a prefix for
    ;; mu4e-update-mail-and-index (bound to "U").
    ;;
    ;; A prefix usually means run in the background, but I don't think I ever want
    ;; that. Change things so a prefix means to call mbsync.
    (defun rjs/mu4e-update-mail-and-index (orig-fun prefix &rest args)
      (interactive "P")
      (if prefix (funcall orig-fun nil) (mu4e-update-index)))
    (advice-add 'mu4e-update-mail-and-index
                :around #'rjs/mu4e-update-mail-and-index)

Links


CategoryMail