2.9 Retrieval and indexing with mu4e

As we have seen, we can do all of the mail retrieval outside of Emacs/mu4e. However, you can also do it from within mu4e.

2.9.1 Basics

To set up mail-retrieval from within mu4e, set the variable mu4e-get-mail-command to the program or shell command you want to use for retrieving mail. You can then get your e-mail using M-x mu4e-update-mail-and-index, or C-S-u in all mu4e-views; alternatively, you can use C-c C-u, which may be more convenient if you use emacs in a terminal.

You can kill the (foreground) update process with q.

It is possible to update your mail and index periodically in the background or foreground, by setting the variable mu4e-update-interval to the number of seconds between these updates. If set to nil, it won’t update at all. After you make changes to mu4e-update-interval, mu4e must be restarted before the changes take effect. By default, this will run in background and to change it to run in foreground, set mu4e-index-update-in-background to nil.

After updating has completed, mu4e keeps the output in a buffer *mu4e-last-update*, which you can use for diagnosis if needed.

2.9.2 Handling errors during mail retrieval

If the mail-retrieval process returns with a non-zero exit code, mu4e shows a warning (unless mu4e-index-update-error-warning is set to nil), but then try to index your maildirs anyway (unless mu4e-index-update-error-continue is set to nil).

Reason for these defaults is that some of the mail-retrieval programs may return non-zero, even when the updating process succeeded; however, it is hard to tell such pseudo-errors from real ones like ‘login failed’.

If you need more refinement, it may be useful to wrap the mail-retrieval program in a shell-script, for example fetchmail returns 1 to indicate ‘no mail’; we can handle that with:

(setq mu4e-get-mail-command "fetchmail -v || [ $? -eq 1 ]")

A similar approach can be used with other mail retrieval programs, although not all of them have their exit codes documented.

2.9.3 Implicit mail retrieval

If you don’t have a specific command for getting mail, for example because you are running your own mail-server, you can leave mu4e-get-mail-command at "true" (the default), in which case mu4e won’t try to get new mail, but still re-index your messages.

2.9.4 Speeding up indexing

If you have a large number of e-mail messages in your store, (re)indexing might take a while. The defaults for indexing are to ensure that we always have correct, up-to-date information about your messages, even if other programs have modified the Maildir.

The downside of this thoroughness (which is the default) is that it is relatively slow, something that can be noticeable with large e-mail corpora on slow file-systems. For a faster approach, you can use the following:

(setq
  mu4e-index-cleanup nil      ;; don't do a full cleanup check
  mu4e-index-lazy-check t)    ;; don't consider up-to-date dirs

In many cases, the mentioned thoroughness might not be needed, and these settings give a very significant speed-up. If it does not work for you (e.g., mu4e fails to find some new messages), simply leave at the default.

Note that you can occasionally run a thorough indexing round using mu4e-update-index-nonlazy.

For further details, please refer to the mu-index manpage; in particular, see .noindex and .noupdate which can help reducing the indexing time.

2.9.5 Example setup

A simple setup could look something like:

(setq
  mu4e-get-mail-command "offlineimap"   ;; or fetchmail, or ...
  mu4e-update-interval 300)             ;; update every 5 minutes

A hook mu4e-update-pre-hook is available which is run right before starting the process. That can be useful, for example, to influence, mu4e-get-mail-command based on the the current situation (location, time of day, ...).

It is possible to get notifications when the indexing process does any updates — for example when receiving new mail. See mu4e-index-updated-hook and some tips on its usage in the FAQ — Frequently Asked Questions.