2019-05-05 14:11:59 -04:00
#+TITLE : email/mu4e
2019-01-05 16:50:08 -05:00
#+DATE : April 8, 2017
#+SINCE : v2.0
#+STARTUP : inlineimages
2017-05-04 10:40:51 +02:00
2019-01-05 16:50:08 -05:00
* Table of Contents :TOC:
2019-08-27 10:50:37 +02:00
- [[#description ][Description ]]
- [[#module-flags ][Module Flags ]]
- [[#plugins ][Plugins ]]
- [[#prerequisites ][Prerequisites ]]
- [[#nixos ][NixOS ]]
- [[#features ][Features ]]
- [[#configuration ][Configuration ]]
- [[#offlineimap ][offlineimap ]]
- [[#mbsync ][mbsync ]]
2020-04-24 12:09:38 +02:00
- [[#mu-and-mu4e ][mu and mu4e ]]
2020-10-01 01:52:58 +08:00
- [[#orgmsg ][OrgMsg ]]
2020-10-14 00:23:17 +08:00
- [[#mu4e-alert ][mu4e-alert ]]
2020-04-01 21:14:58 -04:00
- [[#troubleshooting ][Troubleshooting ]]
- [[#no-such-file-or-directory-mu4e ][=No such file or directory, mu4e= ]]
2020-04-18 18:59:22 -04:00
- [[#void-function-org-time-add-error-on-gentoo ][~(void-function org-time-add)~ error on Gentoo ]]
2019-01-05 16:50:08 -05:00
* Description
2017-05-25 20:08:50 +02:00
This module makes Emacs an email client, using ~mu4e~ .
2017-05-04 10:40:51 +02:00
#+begin_quote
2019-01-05 16:50:08 -05:00
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./
2017-05-25 20:08:50 +02:00
2019-01-05 16:50:08 -05:00
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
2019-01-05 16:50:08 -05:00
** Module Flags
2020-10-14 13:01:46 +08:00
+ =+gmail= Enables gmail-specific configuration for mail ~To~ or ~From~ a gmail
2020-10-01 19:16:33 +08:00
address, or a maildir with ~gmail~ in the name.
2020-10-14 13:01:46 +08:00
+ =+org= Use =org-msg= for composing email in Org, then sending a multipart text
(ASCII export) and HTML message.
2019-01-05 16:50:08 -05:00
** Plugins
2020-10-13 16:43:22 +08:00
+ [[https://github.com/iqbalansari/mu4e-alert ][mu4e-alert ]]
2020-10-14 13:01:46 +08:00
+ =+org=
+ [[https://github.com/jeremy-compostella/org-msg ][org-msg ]]
2020-10-13 16:43:22 +08:00
2019-01-05 16:50:08 -05:00
* Prerequisites
2017-05-25 20:08:50 +02:00
This module requires:
2020-10-30 19:01:46 +08:00
+ Either ~mbsync~ (recommended, default) or ~offlineimap~ (to sync mail with)
2020-04-27 14:09:06 -04:00
+ ~mu~ , to index your downloaded messages and to provide the ~mu4e~ package.
2017-05-25 20:08:50 +02:00
2020-10-14 01:22:53 +08:00
#+name : Install Matrix
| Platform | Install command | Base packages |
|---------------+------------------------+---------------------|
| MacOS | ~brew install <pkgs>~ | =mu= |
| Arch | ~pacman -S <pkgs>~ | (AUR, ~yay -S~) =mu= |
| openSUSE | ~zypper install <pkgs>~ | =maildir-utils=, =mu4e= |
| Fedora | ~dnf install <pkgs>~ | =maildir-utils= |
| Debian/Ubuntu | ~apt-get install <pkgs>~ | =maildir-utils=, =mu4e= |
2019-12-09 10:54:27 +01:00
2020-10-14 01:22:53 +08:00
The install either the =isync= (=mbsync= ) or =offlineimap= package.
2019-12-09 10:54:27 +01:00
2020-10-30 19:01:46 +08: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).
If you use =msmtp= , you'll likely want to add the following to your
=config.el= :
#+begin_src emacs-lisp
(setq sendmail-program "/usr/bin/msmtp"
send-mail-function #'smtpmail-send-it
message-sendmail-f-is-evil t
message-sendmail-extra-arguments '("--read-envelope-from")
message-send-mail-function #'message-send-mail-with-sendmail)
#+end_src
2019-07-19 13:24:25 -05:00
** NixOS
#+BEGIN_SRC nix
environment.systemPackages = with pkgs; [
mu
# And one of the following
isync
offlineimap
];
#+END_SRC
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
2020-10-13 16:44:29 +08:00
* Features
+ Tidied mu4e headers view, with flags from =all-the-icons=
2020-10-14 17:21:20 +08:00
+ Consistent coloring of reply depths (across compose and gnus modes)
2020-10-13 16:44:29 +08:00
+ Prettified =mu4e:main= view
2020-10-13 17:21:52 +08:00
+ Cooperative locking of the =mu= process. Another Emacs instance may request
access, or grab the lock when it's available.
2020-10-14 13:01:46 +08:00
+ =org-msg= integration with =+org= , which can be toggled per-message, with revamped style and
2020-10-14 17:21:20 +08:00
an accent color
2020-10-14 00:23:17 +08:00
+ Gmail integrations with the =+gmail= flag
2020-10-13 16:44:29 +08:00
+ Email notifications with =mu4e-alert= , and (on Linux) a customised notification style
2019-01-05 16:50:08 -05:00
* Configuration
** offlineimap
2020-04-24 12:09:38 +02:00
This module uses =mbsync= by default. To use =offlineimap= , change ~+mu4e-backend~ :
2019-01-05 16:50:08 -05:00
#+BEGIN_SRC emacs-lisp
2019-05-05 14:11:59 -04:00
(setq +mu4e-backend 'offlineimap)
2017-05-04 10:40:51 +02:00
#+END_SRC
2020-04-24 12:09:38 +02:00
Next, you need to write a configuration file for =offlineimap= . Mine can be found
2020-05-29 02:12:41 -05:00
[[https://github.com/hlissner/dotfiles/blob/be0dce5dae8f3cbafaac0cc44269d84b4a742c46/shell/mu/ ][in my dotfiles repository ]]. It is configured to download mail to ~\~ /.mail~. I
2020-04-24 12:09:38 +02:00
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
2020-04-24 12:09:38 +02:00
Next you can download your email with ~offlineimap -o~ . This may take a while,
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
2020-10-14 13:01:46 +08: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.
Next you can download your email with ~mbsync --all~ . This may take a while, but
should be quicker than =offlineimap= ;).
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.
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
use. You can check your version with ~mu --version~ .
For =mu= *>=1.4* you need to run two commands:
#+BEGIN_SRC sh
mu init --maildir ~/.mail --my-address email@example.com
mu index
#+END_SRC
=mu= *<1.4* only requires one command:
#+BEGIN_SRC sh
mu index --maildir ~/.mail
#+END_SRC
2017-05-04 10:40:51 +02:00
Then configure Emacs to use your email address:
#+BEGIN_SRC emacs-lisp :tangle no
2019-05-05 14:11:59 -04:00
;; Each path is relative to `+mu4e-mu4e-mail-path', which is ~/.mail by default
2019-01-05 16:50:08 -05:00
(set-email-account! "Lissner.net"
'((mu4e-sent-folder . "/Lissner.net/Sent Mail")
(mu4e-drafts-folder . "/Lissner.net/Drafts")
(mu4e-trash-folder . "/Lissner.net/Trash")
(mu4e-refile-folder . "/Lissner.net/All Mail")
(smtpmail-smtp-user . "henrik@lissner.net")
2020-04-24 12:09:38 +02:00
(user-mail-address . "henrik@lissner.net") ;; only needed for mu < 1.4
2019-01-05 16:50:08 -05:00
(mu4e-compose-signature . "---\nHenrik Lissner"))
t)
2017-05-04 10:40:51 +02:00
#+END_SRC
2020-10-14 00:23:17 +08:00
*** Gmail
With the =+gmail= flag, integrations are applied which account for the different
behaviour of Gmail.
The integrations are applied when using addresses which contain =@gmail.com= or
have =gmail= in the maildir name. You can use ~+mu4e-gmail-addresses~ when you want
an address to be treated as such but it meets neither conditions (e.g. with
Gsuite).
2020-10-01 01:52:58 +08:00
** OrgMsg
2020-11-18 00:24:27 +08:00
With the =+org= flag, =org-msg= is installed, and ~org-msg-mode~ is enabled before
composing the first message. To disable ~org-msg-mode~ by default, simply
2020-10-01 01:52:58 +08:00
#+BEGIN_SRC emacs-lisp :tangle no
(setq mu4e-compose--org-msg-toggle-next nil)
#+END_SRC
To toggle org-msg for a single message, just apply the universal argument to the
compose or reply command (=SPC u= with ~evil~ , =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.
If you don't like this, simply add
2020-10-14 00:23:17 +08:00
#+begin_src emacs-lisp
2020-11-18 00:24:27 +08:00
(package! mu4e-alert :disable t)
2020-10-14 00:23:17 +08:00
#+end_src
to your [[elisp:(find-file (expand-file-name "packages.el" doom-private-dir)) ][packages.el ]] and it will not be used.
2020-04-01 21:14:58 -04:00
* Troubleshooting
** =No such file or directory, mu4e=
You will get =No such file or directory, mu4e= errors if you don't run ~doom
sync~ after installing =mu= through your package manager.
2020-08-17 02:56:15 +01:00
Some times the the ~mu~ package does not include ~mu4e~ (*cough Ubuntu* ).
if 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 :tangle no
(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")
#+END_SRC
If you have completely lost your install then you can use this handy command!
#+BEGIN_SRC shell
find / -type d -iname '*mu4e* '
# I reccomend rerouting all of the error to /dev/null
find / -type d -iname '*mu4e* ' 2> /dev/null
#+END_SRC
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.