This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
spacemacs/layers/+email/mu4e
Nathanael Schweers 1435c95a79 Fix a previous attempted fix loading mu4e.
mu version 1.8.2 renamed mu-meta to mu-config.  As the variable mu4e-mu-version
is defined in said file the easiest fix seems to be to simply attempt to load
the new one, and only if that fails to load the old version.

Maybe this can be reworked or better yet removed in the future.
2022-07-02 18:41:54 +02:00
..
config.el chore: update copyright headers to 2022 2022-06-03 17:32:20 +02:00
funcs.el chore: update copyright headers to 2022 2022-06-03 17:32:20 +02:00
packages.el Fix a previous attempted fix loading mu4e. 2022-07-02 18:41:54 +02:00
README.org documentation formatting: Sun Jan 3 07:55:29 UTC 2021 2021-01-03 09:11:18 +01:00

Mu4e layer

Description

This layer adds support for the Mu4e email client.

Features:

  • Search, read, reply, move, and delete email.
  • Search-based: no folders, only queries.
  • UI optimized for speed: quick keystrokes for common actions.
  • Very extendable and customizable.
  • Integration with Helm.
  • Maildir summary using mu4e-mailidirs-extension
  • Notifications using mu4e-alert

Install

In order to use this layer you must install mu and mu4e separately. Typically mu4e will be bundled with mu (this is the case on many Linux distributions).

If you're on macOS and install mu using Homebrew, you must specify the location of your Emacs binary at install time using the EMACS environment variable, as well as passing the --with-emacs option:

  brew install mu --with-emacs

If the installation directory of mu4e is not in Emacs' load path, you can set the layer variable mu4e-installation-path, for example:

  (setq-default dotspacemacs-configuration-layers
                '((mu4e :variables
                        mu4e-installation-path "/usr/share/emacs/site-lisp")))

Then add this layer to your ~/.spacemacs. You will need to add mu4e to the existing dotspacemacs-configuration-layers list in this file.

Commands

Global bindings

Key binding Command
SPC a e m Start mu4e
SPC m S or SPC m / Search emails (requires helm)
SPC m C Search contacts (requires helm)
C-x m Compose new message

Headers mode

Key binding Command
J Go to next unread thread marking other mail read on the way
C-j Next header
C-k Previous header

View mode

Key binding Command
J Go to next unread thread marking other mail read on the way
C-j Next header
C-k Previous header

Compose mode

Key binding Command
SPC m c or SPC m , Send the message and exit
SPC m k or SPC m a Kill the message buffer
SPC m s Auto-save and bury the message
SPC m f Add file as attachment
SPC m o Compose in Org-mode syntax

Configuration

Configuration varies too much to give precise instructions. What follows is one example configuration. Refer to mu4e's manual for more detailed configuration instructions.

Maildirs extension

The maildirs extension adds a list of all your maildirs to the main mu4e view that by default shows the unread and total mail counts for all your mail under your base mail directory.

The maildirs extension is not enabled by default. To activate it, change the variable mu4e-use-maildirs-extension to a non-nil value:

  (setq-default dotspacemacs-configuration-layers
                '((mu4e :variables
                        mu4e-use-maildirs-extension t)))

Multiple Accounts

With mu 0.9.16, mu4e comes with a native contexts feature for managing multiple accounts.

The following example is taken from the manual:

  (setq mu4e-contexts
    `( ,(make-mu4e-context
    :name "Private"
    :enter-func (lambda () (mu4e-message "Switch to the Private context"))
    ;; leave-func not defined
    :match-func (lambda (msg)
      (when msg
        (mu4e-message-contact-field-matches msg
          :to "aliced@home.example.com")))
    :vars '(  ( user-mail-address      . "aliced@home.example.com"  )
       ( user-full-name     . "Alice Derleth" )
       ( mu4e-compose-signature .
         (concat
           "Alice Derleth\n"
           "Lauttasaari, Finland\n"))))
       ,(make-mu4e-context
    :name "Work"
    :enter-func (lambda () (mu4e-message "Switch to the Work context"))
    ;; leave-fun not defined
    :match-func (lambda (msg)
      (when msg
        (mu4e-message-contact-field-matches msg
          :to "aderleth@miskatonic.example.com")))
    :vars '(  ( user-mail-address      . "aderleth@miskatonic.example.com" )
       ( user-full-name     . "Alice Derleth" )
       ( mu4e-compose-signature .
         (concat
           "Prof. Alice Derleth\n"
           "Miskatonic University, Dept. of Occult Sciences\n"))))))

  ;; set `mu4e-context-policy` and `mu4e-compose-policy` to tweak when mu4e should
  ;; guess or ask the correct context, e.g.

  ;; start with the first (default) context;
  ;; default is to ask-if-none (ask when there's no context yet, and none match)
  ;; (setq mu4e-context-policy 'pick-first)

  ;; compose with the current context is no context matches;
  ;; default is to ask
  ;; (setq mu4e-compose-context-policy nil)

Note: We used to have a hack to support multiple accounts with older version of mu but we removed it to encourage people to update their version and use the new contexts feature.

Async mode

mu4e can send mails in async mode, which speeds up sending as you do not have to wait for the email to be sent. This is off by default but you can enable it by setting the mu4e-enable-async-operations variable when including the layer.

  (setq-default dotspacemacs-configuration-layers
                '((mu4e :variables
                        mu4e-enable-async-operations t)))

Attachment directory

By default mu4e will save attachment files to $HOME, but this layer changes that to $HOME/Downloads if it exists. You can override this in your dotspacemacs/user-config:

  (setq mu4e-attachment-dir "~/files")

Example configuration

  ;;; Set up some common mu4e variables
  (setq mu4e-maildir "~/.mail"
        mu4e-trash-folder "/Trash"
        mu4e-refile-folder "/Archive"
        mu4e-get-mail-command "mbsync -a"
        mu4e-update-interval nil
        mu4e-compose-signature-auto-include nil
        mu4e-view-show-images t
        mu4e-view-show-addresses t)

  ;;; Mail directory shortcuts
  (setq mu4e-maildir-shortcuts
        '(("/gmail/INBOX" . ?g)
          ("/college/INBOX" . ?c)))

  ;;; Bookmarks
  (setq mu4e-bookmarks
        `(("flag:unread AND NOT flag:trashed" "Unread messages" ?u)
          ("date:today..now" "Today's messages" ?t)
          ("date:7d..now" "Last 7 days" ?w)
          ("mime:image/*" "Messages with images" ?p)
          (,(mapconcat 'identity
                       (mapcar
                        (lambda (maildir)
                          (concat "maildir:" (car maildir)))
                        mu4e-maildir-shortcuts) " OR ")
           "All inboxes" ?i)))

Notifications

mu4e-alert is an extension that provides desktop notifications and adds the count of unread messages to the modeline.

https://raw.githubusercontent.com/iqbalansari/mu4e-alert/master/screenshots/mu4e-alert-in-action.png

For an extended documentation of the available customizations please refer to mu4e-alert's documentation

OS notifications

To enable notifications about new messages, add the following line to your dotspacemacs/user-config:

  (setq mu4e-enable-notifications t)

or use layer variables when you add the layer to dotspacemacs-configuration-layers:

  (mu4e :variables mu4e-enable-notifications t)

By default, notifications will be shown in the *Messages* buffer. To enable desktop notifications about new messages, add the following lines to your dotspacemacs/user-config, according to your operating system and the installed libraries:

  (with-eval-after-load 'mu4e-alert
    ;; Enable Desktop notifications
    (mu4e-alert-set-default-style 'notifications)) ; For Linux.
    ;; (mu4e-alert-set-default-style 'libnotify))  ; Alternative for Linux
    ;; (mu4e-alert-set-default-style 'notifier))   ; For macOS (through the
                                                   ; terminal notifier app).
    ;; (mu4e-alert-set-default-style 'growl))      ; Alternative for macOS.

Mode-line notifications

To enable mode-line display about new messages, add the following line to your dotspacemacs/user-config:

  (setq mu4e-enable-mode-line t)

or use layer variables when you add the layer to dotspacemacs-configuration-layers:

  (mu4e :variables mu4e-enable-mode-line t)

Spacemacs layout integration

A Spacemacs custom layout is defined by the layer. The name and the key binding for it can be customized with the following layer variables:

  • mu4e-spacemacs-layout-name for the layout name,
  • mu4e-spacemacs-layout-binding for the key binding.
  • mu4e-spacemacs-kill-layout-on-exit for automatically removing layout when quitting mu4e.

By default the values are:

  (setq-default dotspacemacs-configuration-layers
                '((mu4e :variables mu4e-spacemacs-layout-name "@Mu4e"
                        mu4e-spacemacs-layout-binding "m"
                        mu4e-spacemacs-kill-layout-on-exit t)))

Org-mu4e integration

Mu4e link support in Org mode

Feature mu4e-org supports links to mu4e messages in Org mode in the form of [[mu4e:msgid::***][link text]]. Enabled by default. You can disable it by setting the mu4e-org-link-support variable when including the layer.

  (setq-default dotspacemacs-configuration-layers
                '((mu4e :variables
                        mu4e-org-link-support nil)))

Composing Org mode messages in mu4e

Feature org-mu4e supports composing emails in Org mode format. Disabled by default. You can enable it by setting the mu4e-org-compose-support variable when including the layer.

  (setq-default dotspacemacs-configuration-layers
                '((mu4e :variables
                        mu4e-org-compose-support t)))

Then when composing, hit keys SPC m o to enable the org-mu4e-compose-org-mode mode. Note that you need to set the variable org-mu4e-convert-to-html if you want the message to be converted before sending.

See also

Refer to the official mu and mu4e documentation for additional info.