mu4e is an email client for Emacs. It’s based on the mu email indexer/searcher.
mu4e first appeared in
This tutorial assumes you have use a tool such as
mpop to retrieve your mail into a maildir folder called
mu from your package manager, then, from the commandline, run:
mu init --maildir=~/mail --email@example.com
From Emacs, download Mu4e with
M-x package install RET mu4e RET and run it with
U to update Mu4e’s mail listing, and
bu to see all your new mail or
j to jump to a maildir folder.
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" "firstname.lastname@example.org" "Emacs is awesome.") ,(my-make-mu4e-context "work" "email@example.com" "A very professional signature.") ,(my-make-mu4e-context "other" "firstname.lastname@example.org" "Plain text mail forever.")))
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)