Spacemacs使用Mu4e收发邮件

安装

  • 安装MBSync与Mu
$sudo apt install isync mu4e
  • 安装Spacemacs Layer
dotspacemacs-configuration-layers  
'(  
  mu4e
  (mu4e :variables
         mu4e-installation-path "/usr/share/emacs/site-lisp"
         mu4e-enable-notifications t)
)

配置

  • ~/.mbsyncrc
IMAPAccount GmailOne  
Host imap.gmail.com  
Port 993  
User gmailone@gmail.com

# 使用明文密码
Pass password

# 使用GPG
PassCmd "gpg -d ~/.mbpasswd.gpg"

UseIMAPS yes  
RequireSSL yes  
CertificateFile /etc/ssl/certs/ca-certificates.crt

IMAPStore gmailone-remote  
Account GmailOne

MaildirStore gmailone-local  
Path ~/Maildir/GmailOne/  
Inbox ~/Maildir/GmailOne/INBOX

Channel gmailone-inbox  
Master :gmailone-remote:  
Slave :gmailone-local:  
Patterns "INBOX"  
Create Both  
Expunge Both  
SyncState *

Channel gmailone-bin  
Master :gmailone-remote:"[Gmail]/Bin"  
Slave :gmailone-local:"[GmailOne].Bin"  
Create Both  
Expunge Both  
SyncState *

Channel gmailone-sent  
Master :gmailone-remote:"[Gmail]/Sent Mail"  
Slave :gmailone-local:"[GmailOne].Sent Mail"  
Create Both  
Expunge Both  
SyncState *

Channel gmailone-all  
Master :gmailone-remote:"[Gmail]/All Mail"  
Slave :gmailone-local:"[GmailOne].All Mail"  
Create Both  
Expunge Both  
SyncState *

Channel gmailone-starred  
Master :gmailone-remote:"[Gmail]/Starred"  
Slave :gmailone-local:"[GmailOne].Starred"  
Create Both  
Expunge Both  
SyncState *

Group gmailone  
Channel gmailone-inbox  
Channel gmailone-sent  
Channel gmailone-trash  
Channel gmailone-all  
Channel gmailone-starred

IMAPAccount GmailTwo  
Host imap.gmail.com  
Port 993  
User gmailtwo@gmail.com  
Pass  
UseIMAPS yes  
RequireSSL yes  
CertificateFile /etc/ssl/certs/ca-certificates.crt


IMAPStore gmailtwo-remote  
Account GmailTwo

MaildirStore gmailtwo-local  
Path ~/Maildir/GmailTwo/  
Inbox ~/Maildir/GmailTwo/INBOX

Channel gmailtwo-inbox  
Master :gmailtwo-remote:  
Slave :gmailtwo-local:  
Patterns "INBOX"  
Create Both  
Expunge Both  
SyncState *

Channel gmailtwo-bin  
Master :gmailtwo-remote:"[Gmail]/Bin"  
Slave :gmailtwo-local:"[GmailTwo].Bin"  
Create Both  
Expunge Both  
SyncState *

Channel gmailtwo-sent  
Master :gmailtwo-remote:"[Gmail]/Sent Mail"  
Slave :gmailtwo-local:"[GmailTwo].Sent Mail"  
Create Both  
Expunge Both  
SyncState *

Channel gmailtwo-all  
Master :gmailtwo-remote:"[Gmail]/All Mail"  
Slave :gmailtwo-local:"[GmailTwo].All Mail"  
Create Both  
Expunge Both  
SyncState *

Channel gmailtwo-starred  
Master :gmailtwo-remote:"[Gmail]/Starred"  
Slave :gmailtwo-local:"[GmailTwo].Starred"  
Create Both  
Expunge Both  
SyncState *

Group gmailtwo  
Channel gmailtwo-inbox  
Channel gmailtwo-sent  
Channel gmailtwo-trash  
Channel gmailtwo-all  
Channel gmailtwo-starred
  • ~/.spacemacs
(defun dotspacemacs/user-config ()

  (setq mu4e-account-alist
        '(("GmailOne"
           (mu4e-sent-messages-behavior delete)
           (mu4e-sent-folder "/Sent Mail")
           (mu4e-drafts-folder "/Drafts")
           (user-mail-address "gmailone@gmail.com")
           (user-full-name "Users"))
           ("GmailTwo"
           (mu4e-sent-messages-behavior delete)
           (mu4e-sent-folder "/Sent Mail")
           (mu4e-drafts-folder "/Drafts")
           (user-mail-address "gmailtwo@gmail.com")
           (user-full-name "Users"))
           ))
)

收取邮件

使用命令mbsync -a拉取邮件,如果.mbsyncrc配置正确,Mbsync就会自动下载邮件到本地的~/Maildir目录下。邮件下载完成后使用命令mu index进行解码,此命令只需执行一次即可,今后在收取邮件时不用在执行。之后打开Spacemacs使用快捷键SPC a M进入Mu4e,即可开始阅读邮件。

发送邮件

  • 使用Emacs原生Emacs-lisp发送邮件

  • ~/.spacemacs

(setq message-send-mail-function 'smtpmail-send-it
        smtpmail-stream-type 'starttls
        starttls-use-gnutls t)

(setq user-full-name "Users")
(setq user-mail-address "gmailone@gmail.com")
(setq smtpmail-smtp-server "smtp.gmail.com")
(setq smtpmail-smtp-service 587)
(setq smtpmail-smtp-user "gmailone@gmail.com")

在Spacemacs的Mu4e界面使用快捷键C创建一封新邮件,编辑完成之后使用快捷键C-c C-c进行发送。

Spacemacs Mu4e Layer README

Spacemacs Mu4e Layer 中文文档

  • Install
  • 安装

In order to use this layer you must install mu and mu4e separately. Typically
mu4e will be bundled with mu (this is the case on many Linux distributions).

为了使用这个Layer,你需要分别安装Mu与Mu4e。但是通常在很多Linux发行版上Mu4e是与Mu捆绑在一起的。

If you're on OS X and install mu using Homebrew, you must specify the
location of your Emacs binary at install time using the EMACS environment
variable, as well as passing the --with-emacs option:

如果你使用macOS,并使用Homebrew安装Mu。则需要在安装时设置Emacs环境变量,使用--with-emacs参数传递:

$brew install mu --with-emacs

If the installation directory of mu4e is not in Emacs’ load path, you can set
the layer variable =mu4e-installation-path=, for example:

如果Mu4e的安装路径不在你的Emacs加载路径之中,你可以使用Mu4e Layer变量mu4e-installation-path进行设置,例如:

  (setq-default dotspacemacs-configuration-layers
                '((mu4e :variables
                        mu4e-installation-path "/usr/share/emacs/site-lisp")))

Then add this layer to your =~/.spacemacs=. You will need to add =mu4e= to the
existing =dotspacemacs-configuration-layers= list in this file.

然后将Mu4e Layer添加到你的~/.spacemacs文件中。你需要添加mu4edotspacemacs-configuration-layers列表之中。

  • Commands
  • 命令

  • Global bindings

  • 全局按键绑定

Keybinding | Command

~SPC a M~ Start mu4e

  • Headers mode
  • 游览模式

Keybinding | Command

~J~ Go to next unread thread marking other mail read on the way

~C-j~ Next header

~C-k~ Previous header

  • View mode
  • 显示模式

Keybinding | Command

~J~ Go to next unread thread marking other mail read on the way

~C-j~ Next header

~C-k~ Previous header

  • Configuration
  • 配置

Configuration varies too much to give precise instructions. What follows is one
example configuration. Refer to mu4e's manual for more detailed configuration
instructions.

不同的配置变化很大,无法给出一个准确的说明。下面是一个简单的示例配置,更加详细的说明,请阅读Mu4e的官方手册。

  • Maildirs extension
  • Maildirs扩展

The maildirs extension adds a list of all your maildirs to the main mu4e view
that by default shows the unread and total mail counts for all your mail under
your base mail directory.

Maildirs 扩展将所有Maildirs中的列表显示在Mu4e的启动主视图之中,默认情况下会显示你的所有未读邮件与邮件总数。

This extension is enabled by default, you can deactivate (and uninstall) it by
adding the package == to your dotfile variable =dotspacemacs-excluded-packages=.

Maildirs扩展默认启用,你可以停用并卸载它。如果要停用(卸载)它,将==(官方原文就什么都没写)添加到你dotfile变量的dotspacemacs-excluded-packages之中。

  • Multiple Accounts
  • 多账户

This layer includes support for multiple sending accounts.

这个Layer支持多个账户发送。

If you have only one account you do not need to define this variable.

如果你只有一个账户,则不需要定义这个变量。

If you have multiple accounts, configure the =mu4e-account-alist= variable:

如果你有多个账户,请配置mu4e-account-alist变量:

  (setq mu4e-account-alist
        '(("gmail"
           ;; Under each account, set the account-specific variables you want.
           ;; 在每个账户下为账户进行单独变量设置。
           (mu4e-sent-messages-behavior delete)
           (mu4e-sent-folder "/gmail/[Gmail]/.Sent Mail")
           (mu4e-drafts-folder "/gmail/[Gmail]/.Drafts")
           (user-mail-address "billy@gmail.com")
           (user-full-name "Billy"))
          ("college"
           (mu4e-sent-messages-behavior sent)
           (mu4e-sent-folder "/college/Sent Items")
           (mu4e-drafts-folder "/college/Drafts")
           (user-mail-address "bb15@college.edu")
           (user-full-name "Billy Bob 15"))))
  (mu4e/mail-account-reset)

The first account listed will be the default account, so variables like
=user-full-name=, which is used by other parts of Emacs, will have their value reset for the default account after sending each email.

第一个账户将是默认账户,所以变量,就像user-full-name,将由Emacs的其他部分使用。它们的变量值会在每次发送邮件后重置为默认账户。

Note that the mu4e layer expects =mu4e-account-alist= to be defined before the
layer is loaded. For example, you can set =mu4e-account-alist= to a dummy
setting in =dotspacemacs/layers=:

注意,这个Mu4e 多账户需要在设置mu4e-account-alist变量之前被启用。例如,你可以将它加到dotspacemacs/layers之中:

(mu4e :variables mu4e-account-alist t)

and then actually set =mu4e-account-alist= later in =dotspacemacs/user-config=.

然后在dotspacemacs/user-config中设置mu4e-account-alist

Make sure you call =mu4e/mail-account-reset= afterward, which will initialize
the given account variables.

如果你需要使用mu4e/mail-account-reset变量,确保在它之后进行设置,因为它会初始化设置好的用户变量。

If you have mu 0.9.16 or later, you can use mu4e's built-in contexts feature
instead (see [[http://www.djcbsoftware.nl/code/mu/mu4e/Contexts.html#Contexts][mu4e's manual]]).

如果你有mu 0.9.16或更高的版本,你可以使用Mu4e内置的上下文功能作为替代。参见手册:http://www.djcbsoftware.nl/code/mu/mu4e/Contexts.html#Contexts

  • Example configuration
  • 示例配置
  ;;; Set up some common mu4e variables
  ;;; 一些常用的Mu4e变量设置
  (setq mu4e-maildir "~/.mail"
        mu4e-trash-folder "/Trash"
        mu4e-refile-folder "/Archive"
        mu4e-get-mail-command "mbsync -a"
        mu4e-update-interval nil
        mu4e-compose-signature-auto-include nil
        mu4e-view-show-images t
        mu4e-view-show-addresses t)

  ;;; Mail directory shortcuts
  ;;; 邮箱路径快捷键
  (setq mu4e-maildir-shortcuts
        '(("/gmail/INBOX" . ?g)
          ("/college/INBOX" . ?c)))

  ;;; Bookmarks
  ;;; 书签
  (setq mu4e-bookmarks
        `(("flag:unread AND NOT flag:trashed" "Unread messages" ?u)
          ("date:today..now" "Today's messages" ?t)
          ("date:7d..now" "Last 7 days" ?w)
          ("mime:image/*" "Messages with images" ?p)
          (,(mapconcat 'identity
                       (mapcar
                        (lambda (maildir)
                          (concat "maildir:" (car maildir)))
                        mu4e-maildir-shortcuts) " OR ")
           "All inboxes" ?i)))
  • Notifications
  • 通知

~mu4e-alert~ is an extension that provides desktop notifications and adds the count of unread messages to the modeline.

mu4e-alert扩展可以提供桌面通知,显示未读消息。

For an extended documentation of the available customizations please refer to
[[https://github.com/iqbalansari/mu4e-alert#customizations][mu4e-alert's documentation]]

有关详细的扩展定制文档,参阅https://github.com/iqbalansari/mu4e-alert#customizations

  • OS notifications
  • 系统通知

To enable notifications about new messages, add the following line to your
~dotspacemacs/user-config~:

如果需要启用新邮件显示系统通知, 你需要添加以下到你的dotspacemacs/user-config:

  (setq mu4e-enable-notifications t)

or use layer variables when you add the layer to

或者在添加它的时候顺便设置一下它的变量

=dotspacemacs-configuration-layers=:

  (mu4e :variables mu4e-enable-notifications t)

By default, notifications will be shown in the ~Messages~ buffer. To enable
desktop notifications about new messages, add the following lines to
your ~dotspacemacs/user-config~, according to your operating system and the
installed libraries:

默认情况下通知会显示在Emacs的MessagesBuffer中。如果要启用新邮件的桌面通知,你需要根据你的操作系统和软件选择以下行之一添加到你的dotspacemacs/user-config中:

  (with-eval-after-load 'mu4e-alert
    ;; Enable Desktop notifications
    (mu4e-alert-set-default-style 'notifications)) ; For linux
    ;; (mu4e-alert-set-default-style 'libnotify))  ; Alternative for linux
    ;; (mu4e-alert-set-default-style 'notifier))   ; For Mac OSX (through the
                                                   ; terminal notifier app)
    ;; (mu4e-alert-set-default-style 'growl))      ; Alternative for Mac OSX
  • Mode-line notifications
  • Mode-line通知 To enable mode-line display about new messages, add the following line to
    your ~dotspacemacs/user-config~:

如果要在Mode-line中显示新邮件信息,添加以下行到你的dotspacemacs/user-config:

  (setq mu4e-enable-mode-line t)

or use layer variables when you add the layer to

=dotspacemacs-configuration-layers=:

或者使用Layer变量设置,在你的dotspacemacs-configuration-layers

  (mu4e :variables mu4e-enable-mode-line t)
  • See also
  • 另请阅读

Refer to the official mu and mu4e documentation for additional info.

  • [[http://www.djcbsoftware.nl/code/mu/mu4e/index.html][mu4e Manual]]

参考Mu与Mu4e的官方文档获取更多信息。

http://www.djcbsoftware.nl/code/mu/mu4e/index.html