使用mu4e收发邮件
1 mu4e收发邮件
- 前言 作为emacs的忠实用户,一直想把emacs配置成自己的邮件客户端.总是被繁琐的配置流程吓退了.直到最近看到一篇 关于使用mu4e收发邮件的文章之后才行动起来,最终使用效果深感欣慰.总体来说解决了如何获取和发送邮件,如何 管理邮件以及如何做界面展示.mu是基于maildir类型的邮件索引和客户端.mu4e是基于mu为emacs开发的客户界面. offlineimap则是基于imap协议的邮件获取客户端.三者搭配起来即可实现emacs邮件客户端.
- 软件安装和配置
offlineimap mac下直接使用brew命令即可安装最新版本的offlineimap.
brew install offlineimap
新建offlineimap的配置文件~/.offlineimaprc.配置好账户信息.出于安全考虑,最好不要在.offlineimaprc中 填写明文密码.所以采用remotepasseval + .offlineimap.py + gpg的方式对口令进行加密.
[general] accounts = xxxx maxsyncaccounts = 3 pythonfile = ~/.offlineimap.py [Account xxxx] localrepository = LocalCxs remoterepository = RemoteCxs [Repository LocalCxs] type = Maildir localfolders = ~/mail [Repository RemoteCxs] type = IMAP remotehost = imap.163.com remoteuser = xxxx@163.com remotepasseval = get_password_emacs("imap.163.com", "xxxx@163.com", 993) ssl = yes sslcacertfile = /usr/local/etc/openssl/cert.pem nametrans = lambda foldername: foldername.decode('imap4-utf-7').encode('utf-8') folderfilter = lambda foldername: foldername in ['Trash','Sent Items', 'Advertisement', 'INBOX', 'Junk E-mail'] maxconnections = 2 realdelete = yes
mu 使用brew命令安装me客户端.mu4e配套代码.
brew install mu --with-emacs
提示configure: error: Package requirements (glib-sharp-2.0 >= 2.4.0) were not met. 需要下载mono安装.
brew instal mono
使用gpg配置密码,避免密码明文写入. 首先安装gpg.
brew install gpg gpg
使用gpg –full-gen-key命令生成密钥.
gpg --symmetric --cipher-algo AES256 .authinfo
配置.offlineimap.py文件.
#!/usr/bin/python import re, os def get_password_emacs(machine, login, port): s = "machine %s login %s port %s password ([^ ]*)\n" % (machine, login, port) p = re.compile(s) authinfo = os.popen( "gpg -dq --batch --passphrase your_password ~/.authinfo.gpg").read() return p.search(authinfo).group(1)
- mu4e
emacs配置 我使用的是spacemacs,所以参考了email layer的部分设置.首先在中启用layer.
(mu4e :variables mu4e-installation-path "/usr/local/Cellar/mu/mu4e" mu4e-enable-mode-line t mu4e-enable-notifications t mu4e-mu-binary (executable-find "/usr/local/bin/mu")) ;;; Set up some common mu4e variables (setq mu4e-maildir (expand-file-name "~/mail") mu4e-sent-folder "/Sent Items" mu4e-refile-folder "/Archive" mu4e-drafts-folder "/drafts" mu4e-trash-folder "/Trash" mu4e-get-mail-command "offlineimap" mu4e-update-interval 300 mu4e-compose-signature-auto-include nil mu4e-view-show-images t mu4e-html2text-command 'mu4e-shr2text shr-color-visible-luminance-min 80 mu4e-view-show-addresses t) ;; save attachment to my desktop (this can also be a function) (setq mu4e-attachment-dir "~/Downloads") ;;; Mail directory shortcuts (setq mu4e-maildir-shortcuts '(("/INBOX" . ?i) ("/Sent Items" . ?s))) (setq mu4e-maildirs-extension-custom-list '("/INBOX" "/Advertisement" "/Junk E-mail")) ;; 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))) ;; configuration for sending mail (setq user-full-name "chenxxxxxxx") (setq user-mail-address "xxxx@163.com") (setq mu4e-compose-signature (concat "Chen xxxx\n" "QQ: xxxx\n" "\n") mu4e-compose-signature-auto-include t) (setq message-send-mail-function 'smtpmail-send-it smtpmail-stream-type 'starttls smtpmail-starttls-credentials '(("smtp.163.com" 25 nil nil)) smtpmail-default-smtp-server "smtp.163.com" smtpmail-smtp-server "smtp.163.com" smtpmail-smtp-service 25 smtpmail-debug-info t) (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
- 遗留问题
- 需要完美解决fetch命令乱码问题.
- 参考链接