I am using
mu4e for email in Emacs, and it is currently only
configured for one mail account, and I set key to view different inbox. I wonder how to use mu4e for managing multiple email accounts?
I am using
I'm using mu4e with two accounts. Each account has its own maildir:
~/Mail | +---- work | `---- private
The manual comes with an example function to choose an account:
(defun my-mu4e-set-account () "Set the account for composing a message." (let* ((account (if mu4e-compose-parent-message (let ((maildir (mu4e-message-field mu4e-compose-parent-message :maildir))) (string-match "/\\(.*?\\)/" maildir) (match-string 1 maildir)) (completing-read (format "Compose with account: (%s) " (mapconcat #'(lambda (var) (car var)) my-mu4e-account-alist "/")) (mapcar #'(lambda (var) (car var)) my-mu4e-account-alist) nil t nil nil (caar my-mu4e-account-alist)))) (account-vars (cdr (assoc account my-mu4e-account-alist)))) (if account-vars (mapc #'(lambda (var) (set (car var) (cadr var))) account-vars) (error "No email account found")))) ;; ask for account when composing mail (add-hook 'mu4e-compose-pre-hook 'my-mu4e-set-account)
For that to work you will also need the
(defvar my-mu4e-account-alist '(("private" (user-mail-address "email@example.com") (user-full-name "My Name") (mu4e-sent-folder "/private/Sent Items") (mu4e-drafts-folder "/private/Drafts") (mu4e-trash-folder "/private/Deleted Items") (mu4e-refile-folder "/private/Archive")) ("work" (user-mail-address "firstname.lastname@example.org") (mu4e-sent-folder "/work/Sent Items") (mu4e-drafts-folder "/work/Drafts") (mu4e-trash-folder "/work/Deleted Items") (mu4e-refile-folder "/work/Archives")))) (setq mu4e-user-mail-address-list (mapcar (lambda (account) (cadr (assq 'user-mail-address account))) my-mu4e-account-alist))
You can simply switch between mail folders with
j, as long as all of your maildirs are subdirectories of
I'm actually using a more elaborate function for
mu4e-refile-folder to avoid moving emails from one maildir over to another, but the information above should be sufficient to use multiple accounts.
I'm using two different accounts that I want to mix as little as possible.
offlineimap is configured with two accounts, one delivering mail into
~/.maildir-work the other one into
My configuration for mu4e uses the new context mechanism:
(setq mu4e-contexts `( ,(make-mu4e-context :name "home" :match-func (lambda (_) (string-equal "home" (mu4e-context-name mu4e~context-current))) :enter-func '() :leave-func (lambda () (mu4e-clear-caches)) :vars '((mu4e-maildir . "~/.maildir-home") (mu4e-mu-home . "~/.mu-home") (mu4e-get-mail-command . "offlineimap -a Home") ...)) ,(make-mu4e-context :name "work" :match-func (lambda (_) (string-equal "work" (mu4e-context-name mu4e~context-current))) :enter-func '() :leave-func (lambda () (mu4e-clear-caches)) :vars '((mu4e-maildir . "~/.maildir-work") (mu4e-mu-home . "~/.mu-work") (mu4e-get-mail-command . "offlineimap -a Work") ...))))
I'm using a setup very similar to Magnus', and just wanted to add that
(mu4e-quit) exists, and it works fine for cleaning up accounts without restarting. Actual mechanism:
(defun mail-gmail () (interactive) (setenv "MAILDIR" "/Users/foo/Maildir/gmail") (setenv "MU_HOME" "/Users/foo/.mu/gmail") (setq mu4e-maildir "/Users/foo/Maildir/gmail") (setq user-mail-address "...") (mu4e-quit))