2022-03-28 15:03:21 +02:00
#+title : :email mu4e
#+subtitle : The great filter Hanson hadn't anticipated
#+created : April 08, 2017
#+since : 2.0.3
2021-10-16 01:27:18 +02:00
* Description :unfold:
2021-08-04 22:41:21 +03:00
This module makes Emacs an email client, using [[https://www.djcbsoftware.nl/code/mu/mu4e.html ][mu4e ]].
2017-05-04 10:40:51 +02:00
2023-09-14 00:03:55 +01:00
- Tidied mu4e headers view, with flags from [[doom-package:nerd-icons ]].
2021-10-16 01:27:18 +02:00
- Consistent coloring of reply depths (across compose and gnus modes).
- Prettified =mu4e:main= view.
- Cooperative locking of the =mu= process. Another Emacs instance may request
access, or grab the lock when it's available.
2022-09-26 02:19:42 +08:00
- [[doom-package:org-msg ]] integration with [[doom-module:+org ]], which can be toggled per-message, with revamped
2021-10-16 01:27:18 +02:00
style and an accent color.
2022-09-26 02:19:42 +08:00
- Gmail integrations with the [[doom-module:+gmail ]] flag.
- Email notifications with [[doom-package:mu4e-alert ]], and (on Linux) a customised notification
2021-10-16 01:27:18 +02:00
style.
2017-05-25 20:08:50 +02:00
2021-10-16 01:27:18 +02:00
#+begin_quote
💡 I want to live in Emacs, but as we all know, living is incomplete without
email. So I prayed to the text editor gods and they (I) answered.
Emacs+evil's editing combined with org-mode for writing emails? /Yes
please./
It uses ~mu4e~ to read my email, but depends on ~offlineimap~ (to sync my
email via IMAP) and ~mu~ (to index my mail into a format ~mu4e~ can
understand).
2017-05-04 10:40:51 +02:00
#+end_quote
2021-07-31 01:22:21 +08:00
** Maintainers
2021-10-16 01:27:18 +02:00
- [[doom-user: ][@tecosaur ]]
[[doom-contrib-maintainer: ][Become a maintainer? ]]
** Module flags
- +gmail ::
Enable gmail-specific configuration for mail ~To~ or ~From~ a gmail address,
or a maildir with ~gmail~ in the name.
- +org ::
2022-09-26 02:19:42 +08:00
Use [[doom-package:org-msg ]] for composing email in Org, then sending a multipart text (ASCII
2021-10-16 01:27:18 +02:00
export) and HTML message.
2021-07-31 01:22:21 +08:00
2021-10-16 01:27:18 +02:00
** Packages
2022-09-26 02:19:42 +08:00
- [[doom-package:mu4e-alert ]]
- [[doom-package:org-msg ]] if [[doom-module:+org ]]
2019-01-05 16:50:08 -05:00
2021-10-16 01:27:18 +02:00
** TODO Hacks
#+begin_quote
2023-09-16 20:19:11 +02:00
This module's hacks haven't been documented yet. [[doom-contrib-module: ][Document them? ]]
2021-10-16 01:27:18 +02:00
#+end_quote
** TODO Changelog
# This section will be machine generated. Don't edit it by hand.
/This module does not have a changelog yet./
* Installation
[[id:01cffea4-3329-45e2-a892-95a384ab2338 ][Enable this module in your ~doom!~ block. ]]
2020-10-13 16:43:22 +08:00
2017-05-25 20:08:50 +02:00
This module requires:
2021-10-16 01:27:18 +02:00
- [[https://www.djcbsoftware.nl/code/mu/ ][mu ]], to index your downloaded messages and to provide the [[https://www.djcbsoftware.nl/code/mu/mu4e.html ][mu4e ]] package.
- A program to sync your mail. This module comes with builtin support for [[https://isync.sourceforge.io/ ][mbsync ]]
(recommended, default) or [[http://www.offlineimap.org/ ][offlineimap ]] but you can sync mail in other ways too.
2017-05-25 20:08:50 +02:00
2020-10-14 01:22:53 +08:00
#+name : Install Matrix
2023-09-14 00:03:55 +01:00
| Platform | Install command | Base packages |
|---------------+--------------------------+---------------------|
| MacOS | ~$ brew install <pkgs>~ | =mu= |
2021-10-16 01:27:18 +02:00
| Arch | ~$ pacman -S <pkgs>~ | (AUR, ~$ yay -S~) =mu= |
| openSUSE | ~$ zypper install <pkgs>~ | =maildir-utils=, =mu4e= |
2023-09-14 00:03:55 +01:00
| Fedora | ~$ dnf install <pkgs>~ | =maildir-utils= |
2021-10-16 01:27:18 +02:00
| Debian/Ubuntu | ~$ apt-get install <pkgs>~ | =maildir-utils=, =mu4e= |
2019-12-09 10:54:27 +01:00
2021-08-04 01:12:19 +02:00
Then install either the =isync= (=mbsync= ) or =offlineimap= package.
2019-12-09 10:54:27 +01:00
2021-10-16 01:27:18 +02:00
To send mail, mu4e uses [[https://www.gnu.org/software/emacs/manual/html_mono/smtpmail.html ][smtpmail ]] (an Emacs library) by default. You can also run
a local SMTP server like =sendmail= or =postfix= , or use an SMTP forwarder such
as =msmtp= (recommended).
2020-10-30 19:01:46 +08:00
2021-10-16 01:27:18 +02:00
If you use =msmtp= :
2020-10-30 19:01:46 +08:00
#+begin_src emacs-lisp
2021-10-16 01:27:18 +02:00
;; add to $DOOMDIR/config.el
2021-09-04 16:09:26 +03:00
(after! mu4e
(setq sendmail-program (executable-find "msmtp")
2020-10-30 19:01:46 +08:00
send-mail-function #'smtpmail-send-it
message-sendmail-f-is-evil t
message-sendmail-extra-arguments '("--read-envelope-from")
2021-09-04 16:09:26 +03:00
message-send-mail-function #'message-send-mail-with-sendmail))
2020-10-30 19:01:46 +08:00
#+end_src
2019-07-19 13:24:25 -05:00
** NixOS
2021-10-16 01:27:18 +02:00
#+begin_src nix
2019-07-19 13:24:25 -05:00
environment.systemPackages = with pkgs; [
mu
# And one of the following
isync
offlineimap
];
2021-10-16 01:27:18 +02:00
#+end_src
2019-07-19 13:24:25 -05:00
2020-05-09 20:58:15 -05:00
[[https://github.com/Emiller88/dotfiles/blob/5eaabedf1b141c80a8d32e1b496055231476f65e/modules/shell/mail.nix ][An example of setting up mbsync and mu with home-manager ]]
2019-01-05 16:50:08 -05:00
2021-10-16 01:27:18 +02:00
* TODO Usage
#+begin_quote
2023-09-16 20:19:11 +02:00
This module has no usage documentation yet. [[doom-contrib-module: ][Write some? ]]
2021-10-16 01:27:18 +02:00
#+end_quote
2019-01-05 16:50:08 -05:00
2021-10-16 01:27:18 +02:00
* TODO Configuration
#+begin_quote
2023-09-16 20:19:11 +02:00
/This module's configuration documentation is incomplete./ [[doom-contrib-module: ][Complete it? ]]
2021-10-16 01:27:18 +02:00
#+end_quote
2019-01-05 16:50:08 -05:00
2021-10-16 01:27:18 +02:00
** offlineimap
This module uses =mbsync= by default. To use =offlineimap= , change
~+mu4e-backend~ :
#+begin_src emacs-lisp
2019-05-05 14:11:59 -04:00
(setq +mu4e-backend 'offlineimap)
2021-10-16 01:27:18 +02:00
#+end_src
2017-05-04 10:40:51 +02:00
2021-10-16 01:27:18 +02:00
Next, you need to write a configuration file for =offlineimap= . Mine can be
found [[https://github.com/hlissner/dotfiles/blob/be0dce5dae8f3cbafaac0cc44269d84b4a742c46/shell/mu/ ][in my dotfiles repository ]]. It is configured to download mail to
~\~ /.mail~. I use [[https:/ /www.passwordstore.org/ ][unix pass]] to securely store my login credentials. You can find
a *very* detailed configuration [[https://github.com/OfflineIMAP/offlineimap/blob/master/offlineimap.conf ][here ]].
2017-05-04 10:40:51 +02:00
2021-10-16 01:27:18 +02:00
Next you can download your email with ~$ offlineimap -o~ . This may take a while,
2020-04-24 12:09:38 +02:00
especially if you have thousands of mails.
2020-05-29 02:07:25 -05:00
You can now proceed with the [[#mu-and-mu4e ][mu and mu4e ]] section.
2020-04-24 12:09:38 +02:00
** mbsync
The steps needed to set up =mu4e= with =mbsync= are very similar to the ones for
2020-05-29 02:07:25 -05:00
[[#offlineimap ][offlineimap ]].
2020-04-24 12:09:38 +02:00
2021-10-16 01:27:18 +02:00
Start with writing a =~/.mbsyncrc= . An example for Gmail can be found on
2020-10-14 00:14:34 +08:00
[[http://pragmaticemacs.com/emacs/migrating-from-offlineimap-to-mbsync-for-mu4e/ ][pragmaticemacs.com ]]. A non-Gmail example is available as a gist [[https://gist.github.com/agraul/60977cc497c3aec44e10591f94f49ef0 ][here ]]. The [[http://isync.sourceforge.net/mbsync.html][manual
2020-04-24 12:09:38 +02:00
page]] contains all needed information to set up your own.
2021-10-16 01:27:18 +02:00
Next you can download your email with ~$ mbsync --all~ . This may take a while,
but should be quicker than =offlineimap= ;).
2020-04-24 12:09:38 +02:00
2020-05-29 02:07:25 -05:00
You can now proceed with the [[#mu-and-mu4e ][mu and mu4e ]] section.
2020-04-24 12:09:38 +02:00
2020-10-14 00:14:34 +08:00
*** Faster syncing
It's possible to use IMAP IDLE to be quickly notified of updates, then use a
tailored =mbsync= command to just fetch the new changes.
If this is of interest, this approach can be seen [[https://tecosaur.github.io/emacs-config/config.html#fetching ][in @tecosaur's config ]] where
[[https://gitlab.com/shackra/goimapnotify ][goimapnotify ]] is used for this.
2021-10-16 01:27:18 +02:00
2021-08-04 01:12:19 +02:00
** Fetching your mail in other ways
You also have the possiblity to invoke an arbitary shell command to fetch your
mail by disabling this module's backend selection and setting the value of the
2021-10-16 01:27:18 +02:00
~mu4e-get-mail-command~ to the command you want to execute:
#+begin_src emacs-lisp
2021-08-04 01:12:19 +02:00
(setq +mu4e-backend nil)
(after! mu4e
(setq mu4e-get-mail-command "your_command"))
2021-10-16 01:27:18 +02:00
#+end_src
2021-08-04 01:12:19 +02:00
If your command prompts you for a passphrase, you might want to change the value
2022-08-18 00:13:13 +02:00
of the ~mu4e~get-mail-password-regexp~ variable
2022-09-26 02:19:42 +08:00
(~mu4e--get-mail-password-regexp~ if =mu= *>=1.8* ) such that [[doom-package:mu4e ]] will recognize
2022-08-18 00:13:13 +02:00
the prompt and let you provide the passphrase from within Emacs.
2020-10-14 00:14:34 +08:00
2020-04-24 12:09:38 +02:00
** mu and mu4e
You should have your email downloaded already. If you have not, you need to set
=offlineimap= or =mbsync= up before you proceed.
2020-10-14 00:23:17 +08:00
Before you can use =mu4e= or the CLI program =mu= , you need to index your email
2020-04-24 12:09:38 +02:00
initially. How to do that differs a little depending on the version of =mu= you
2021-10-16 01:27:18 +02:00
use. You can check your version with ~$ mu --version~ .
2020-04-24 12:09:38 +02:00
For =mu= *>=1.4* you need to run two commands:
2021-10-16 01:27:18 +02:00
#+begin_src sh
2020-04-24 12:09:38 +02:00
mu init --maildir ~/.mail --my-address email@example.com
mu index
2021-10-16 01:27:18 +02:00
#+end_src
2020-04-24 12:09:38 +02:00
=mu= *<1.4* only requires one command:
2021-10-16 01:27:18 +02:00
#+begin_src sh
mu index --maildir $HOME/.mail
#+end_src
2017-05-04 10:40:51 +02:00
2021-10-16 01:27:18 +02:00
Be sure to replace =$HOME/.mail= with the directory containing your mail.
2021-08-04 00:43:47 +02:00
2017-05-04 10:40:51 +02:00
Then configure Emacs to use your email address:
2021-10-16 01:27:18 +02:00
#+begin_src emacs-lisp
2021-08-04 00:43:47 +02:00
;; Each path is relative to the path of the maildir you passed to mu
2021-11-14 17:34:17 +01:00
(set-email-account! "bar.com"
'((mu4e-sent-folder . "/bar.com/Sent Mail")
(mu4e-drafts-folder . "/bar.com/Drafts")
(mu4e-trash-folder . "/bar.com/Trash")
(mu4e-refile-folder . "/bar.com/All Mail")
(smtpmail-smtp-user . "foo@bar.com")
(user-mail-address . "foo@bar.com") ;; only needed for mu < 1.4
(mu4e-compose-signature . "---\nYours truly\nThe Baz"))
2019-01-05 16:50:08 -05:00
t)
2021-10-16 01:27:18 +02:00
#+end_src
2020-10-14 00:23:17 +08:00
2021-07-10 13:47:44 -05:00
If you use multiple email accounts, defining them with ~set-email-account!~ will
automatically set the appropriate account context when replying to emails in
that account's maildir. ~mu4e-context-policy~ and ~mu4e-compose-context-policy~
can be modified to change context behavior when opening mu4e and composing
email:
#+begin_src emacs-lisp
(setq mu4e-context-policy 'ask-if-none
mu4e-compose-context-policy 'always-ask)
#+end_src
If you send mail from various email aliases for different services,
~+mu4e-personal-addresses~ can be set per-context with ~set-email-account!~ . If
you are not replying to an email to or from one of the specified aliases, you
will be prompted for an alias to send from.
2020-10-14 00:23:17 +08:00
*** Gmail
2022-09-26 02:19:42 +08:00
With the [[doom-module:+gmail ]] flag, integrations are applied which account for the different
2020-10-14 00:23:17 +08:00
behaviour of Gmail.
2021-01-17 13:49:10 -06:00
The integrations are applied to addresses with /both/ "@gmail.com" in the
account address and "gmail" in the account maildir, as well as accounts listed
in ~+mu4e-gmail-accounts~ . Any domain can be specified, so G Suite accounts can
benefit from the integrations:
#+begin_src emacs-lisp
;; if "gmail" is missing from the address or maildir, the account must be listed here
(setq +mu4e-gmail-accounts '(("hlissner@gmail.com" . "/hlissner")
("example@example.com" . "/example")))
#+end_src
2021-10-16 01:27:18 +02:00
If you only use Gmail, you can improve performance due to the way Gmail presents
messages over IMAP:
2021-01-17 13:49:10 -06:00
#+begin_src emacs-lisp
;; don't need to run cleanup after indexing for gmail
(setq mu4e-index-cleanup nil
;; because gmail uses labels as folders we can use lazy check since
;; messages don't really "move"
mu4e-index-lazy-check t)
#+end_src
Also, note that Gmail's IMAP settings must have "When I mark a message in IMAP
as deleted: Auto-Expunge off - Wait for the client to update the server." and
"When a message is marked as deleted and expunged from the last visible IMAP
folder: Move the message to the trash" for the integrations to work as expected.
2020-10-14 00:23:17 +08:00
2024-04-02 10:17:24 +00:00
** Sending mail (SMTP)
Once you're able to fetch your mail, the next step is to configure =mu4e= to
send mail via SMTP. All of the following snippets are meant to be part of your
~set-email-account!~ block:
*** SMTP server configuration
#+begin_src emacs-lisp
;; In `set-email-account!'
(smtpmail-smtp-user . "foo@bar.com") ; or just 'foo', depending on your provider
(smtpmail-smtp-server . "smtp.bar.com") ; depends on your provider
#+end_src
*** Authentication
Most SMTP servers require you to authenticate with your username and a password
before sending mail. Emacs will prompt you for this password when you attempt to
send mail. You can store this password as described in [[elisp:(info "(emacs) Authentication") ][the relevant info node ]].
Alternately, if you're already using =pass= to store your passwords, you can use
the [[doom-module::tools pass +auth ]] module as an auth source. The corresponding
entry in your password store should have the same name as your SMTP server (for
example, it might be called =smtp.bar.com= ). You may also need to run the function
~auth-source-pass-enable~ at some point.
Emacs will first attempt to send mail without supplying credentials, and expects
the server to communicate that needs credentials. Some servers (eg. Gmail) will
instead abort with an error if they don't recieve credentials on the first
attempt. To get around this, you can set
~smtpmail-servers-requiring-authorization~ to a regex matching the name of your
server:
#+begin_src emacs-lisp
;; In `set-email-account!'
(smtpmail-servers-requiring-authorization . "smtp\\.bar\\.com")
#+end_src
**** Gmail
Gmail does not support standard SMTP authentication by default, instead
expecting applications to perform OAuth. However, it still supports a much
simpler method - it allows you to generate an 'app password', which can be used
as a regular SMTP password. You will need to generate an app password in Gmail's
settings.
*** Connection type
Emacs supports three types of SMTP connections: ~plain~ (unencrypted,
conventionally port 25), ~ssl~ (conventionally port 465), and ~starttls~
(conventionally port 587). This module defaults to ~starttls~ , which is the most
modern and recommended option. However, some servers may not support it (you'll
usually get a 'connection closed' or 'connection reset' error in this case), or
a firewall somewhere in your network may be blocking the port (you'll get a
'network unreachable' error, or similar). In such a case, you may want to change
the defaults:
#+begin_src emacs-lisp
;; In `set-email-account!'
;; example: ssl on port 465
(smtpmail-smtp-service . 465)
(smtpmail-stream-type . ssl)
#+end_src
*** Sending mail asynchronously
Normally, =mu4e= will block Emacs while sending mail, which can be annoying when
you're on a slow connection and the mail takes a long time to send. There is a
workaround [[elisp:(info "(mu4e) Writing messages") ][in mu4e's manual ]] that uses the [[doom-package:async ]] library. To use it,
you need to include it in your ~set-email-account!~ block:
#+begin_src emacs-lisp
;; In `set-email-account!'
(send-mail-function . async-smtpmail-send-it)
(message-send-mail-function . async-smtpmail-send-it)
#+end_src
If you're using [[doom-module::tools pass +auth ]], you also need to ensure that the child
Emacs process can access your password-store:
#+begin_src emacs-lisp
;; This goes OUTSIDE your `set-email-account!' block!
(require 'smtpmail-async)
(add-hook 'async-smtpmail-before-send-hook #'auth-source-pass-enable)
#+end_src
2020-10-01 01:52:58 +08:00
** OrgMsg
2022-09-26 02:19:42 +08:00
With the [[doom-module:+org ]] flag, [[doom-package:org-msg ]] is installed, and ~org-msg-mode~ is enabled before
2021-10-16 01:27:18 +02:00
composing the first message. To disable ~org-msg-mode~ by default:
#+begin_src emacs-lisp
;; add to $DOOMDIR/config.el
2022-06-27 15:16:44 -04:00
(setq +mu4e-compose-org-msg-toggle-next nil)
2021-10-16 01:27:18 +02:00
#+end_src
2020-10-01 01:52:58 +08:00
To toggle org-msg for a single message, just apply the universal argument to the
2022-09-26 02:19:42 +08:00
compose or reply command ([[kbd: ][SPC u ]] with [[doom-package:evil ]], [[kbd: ][C-u ]] otherwise).
2017-05-25 20:08:50 +02:00
2020-10-14 17:21:20 +08:00
The accent color that Doom uses can be customised by setting
~+org-msg-accent-color~ to a CSS color string.
2020-10-14 00:23:17 +08:00
2020-11-18 00:24:27 +08:00
** mu4e-alert
This provides notifications through the [[https://github.com/jwiegley/alert ][alert ]] library.
2021-10-16 01:27:18 +02:00
If you don't like this use:
2020-10-14 00:23:17 +08:00
#+begin_src emacs-lisp
2021-10-16 01:27:18 +02:00
;; add to $DOOMDIR/packages.el
2020-11-18 00:24:27 +08:00
(package! mu4e-alert :disable t)
2020-10-14 00:23:17 +08:00
#+end_src
2022-01-15 10:32:59 +07:00
** Enabling automatic email fetching
By default, periodic email update is *disabled* . To enable periodic
mail retrieval/indexing, change the value of ~mu4e-update-interval~ :
#+begin_src emacs-lisp
(setq mu4e-update-interval 60)
#+end_src
2020-04-01 21:14:58 -04:00
* Troubleshooting
2021-10-16 01:27:18 +02:00
[[doom-report: ][Report an issue? ]]
2020-04-01 21:14:58 -04:00
** =No such file or directory, mu4e=
2021-10-16 01:27:18 +02:00
You will get =No such file or directory, mu4e= errors if you don't run ~$ doom
2020-04-01 21:14:58 -04:00
sync~ after installing =mu= through your package manager.
2020-08-17 02:56:15 +01:00
2024-03-13 08:16:29 +08:00
Some times the ~mu~ package does not include ~mu4e~ (*cough Ubuntu* ). if
2021-10-16 01:27:18 +02:00
that's the case you will need to [[https://github.com/djcb/mu ][install ]] it and add it to your ~load-path~ you
can do that by:
#+begin_src emacs-lisp
2020-08-17 02:56:15 +01:00
(add-to-list 'load-path "your/path/to/mu4e")
;; if you installed it using your package manager
(add-to-list 'load-path "/usr/share/emacs/site-lisp/mu4e")
;; if you built from source
(add-to-list 'load-path "/usr/local/share/emacs/site-lisp/mu4e")
2021-10-16 01:27:18 +02:00
#+end_src
2020-08-17 02:56:15 +01:00
2021-10-16 01:27:18 +02:00
If you have completely lost your install then you can use:
#+begin_src sh
2020-08-17 02:56:15 +01:00
find / -type d -iname '*mu4e* '
2021-08-03 02:40:15 +08:00
# I recommend rerouting all of the errors to /dev/null
2020-08-17 02:56:15 +01:00
find / -type d -iname '*mu4e* ' 2> /dev/null
2021-10-16 01:27:18 +02:00
#+end_src
2020-08-17 02:56:15 +01:00
2020-04-18 18:59:22 -04:00
** ~(void-function org-time-add)~ error on Gentoo
Gentoo users will see this error because [[https://gitweb.gentoo.org/repo/gentoo.git/tree/net-mail/mu/files/70mu-gentoo.el#n2][the =net-mail/mu= package eagerly loads
=mu4e= (which pulls in =org= ) much too early]]; before Emacs reads =~/.emacs.d= .
So early, that it loads the built-in version of org-mode, rather than the newer
version that Doom installs.
Later versions of the =net-mail/mu= package have [[https://gitweb.gentoo.org/repo/gentoo.git/commit/net-mail/mu?id=770e1fccb119fbce8ba6d16021a3598123f212ff ][fixed this issue ]], but you may
need to switch to the unstable build of =net-mail/mu= to see it.
2021-10-16 01:27:18 +02:00
* Frequently asked questions
/This module has no FAQs yet./ [[doom-suggest-faq: ][Ask one? ]]
* TODO Appendix
#+begin_quote
2023-09-16 20:19:11 +02:00
This module has no appendix yet. [[doom-contrib-module: ][Write one? ]]
2021-10-16 01:27:18 +02:00
#+end_quote