mu4e-多个帐户


22

mu4e在Emacs中使用电子邮件,目前仅针对一个邮件帐户进行配置,并且设置了密钥以查看其他收件箱。我想知道如何使用mu4e管理多个电子邮件帐户吗?

Answers:


17

我正在使用具有两个帐户的mu4e。每个帐户都有自己的maildir:

~/Mail
|
+---- work
|
`---- private

该手册附带一个用于选择帐户的示例功能:

(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)

为此,您还需要my-mu4e-account-alist

(defvar my-mu4e-account-alist
  '(("private"
     (user-mail-address  "private@domain.net")
     (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  "work@domain.net")
     (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))

j只要您的所有maildirs是的子目录,您都可以简单地在邮件文件夹之间切换mu4e-maildir

实际上,我在使用更复杂的功能,mu4e-trash-foldermu4e-refile-folder避免将电子邮件从一个maildir转移到另一个maildir,但是上面的信息对于使用多个帐户应该足够了。


我正在努力理解mu4e如何知道要显示哪个收件箱。没有任何mu4e-inbox-folder变数,当我按此按钮时,ji我会从我所有的帐户中收到传入的邮件,而不仅仅是工作或私人环境。
AstroFloyd

6

我正在使用两个我想尽可能少混合的帐户。

offlineimap配置有两个帐户,一个帐户将邮件发送到~/.maildir-work另一个帐户中~/.maildir-home

我对mu4e的配置使用了新的上下文机制:

(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")
                   ...))))

我在使此示例正常工作时遇到了麻烦。根据文档mu4e-maildirmu4e-mu-home在不先退出mu4e的情况下,和变量是不可更改的。我在此处设置了更多细节。
kostajh's

确实,我不得不在切换时重新启动Emacs。对我来说还是值得的。
马格努斯

2

我正在使用与Magnus非常相似的设置,只是想添加(mu4e-quit)存在的设置,它可以很好地清理帐户而无需重新启动。实际机制:

(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))
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.