我的工作生活重度依赖Gmail和Emacs,它们的结合,让我欣喜万分。通过Emacs Gnus收发Gmail之后,我不用翻墙了,因为IMAP不是HTTP,没有被墙。我能很惬意的在Emacs中收发,检索Gmail邮件。
如何配置的细节请参考一篇非常重要的文章:
http://www.mostlymaths.net/2010/12/emacs-30-day-challenge-using-gnus-to.html
现在看一下我的配置文件.gnus.el
(setq user-full-name "chenshu")
(setq user-mail-address "csfreebird@gmail.com")
;;;;;;;;;;;;;;;;;;;;
;; 语言环境设定
;;;;;;;;;;;;;;;;;;;;
(set-language-environment 'Chinese-GB)
(setq gnus-default-charset 'chinese-iso-8bit
gnus-group-name-charset-group-alist '((".*" . cn-gb-2312))
gnus-summary-show-article-charset-alist
'((1 . cn-gb-2312)
(2 . gb18030)
(3 . chinese-iso-8bit)
(4 . gbk)
(5 . big5)
(6 . utf-8))
gnus-newsgroup-ignored-charsets
'(unknown-8bit x-unknown iso-8859-1))
;;;;;;;;;;;;;;;;;;;;
;;自动显示图片
;;;;;;;;;;;;;;;;;;;;
(auto-image-file-mode)
(setq mm-inline-large-images t)
(add-to-list 'mm-attachment-override-types "image/*")
;;各种发送设置
;;;;;;;;;;;;;;;;;;;;
(setq gnus-posting-styles
'((".*"
(name "sheismylife")
(address "csfreebird@gmail.com")
(signature "http://blog.csdn.net/sheismylife\n UBuntu11.10、Emacs+Gnus\n")
))
)
;; You need this to be able to list all labels in gmail
;;(setq gnus-ignored-newsgroups "")
(require 'nnir)
;; And this to configure gmail imap
(setq gnus-select-method '(nnimap "gmail" (nnimap-address "imap.gmail.com") (nnimap-server-port 993) (nnimap-stream ssl) (nnir-search-engine imap)))
(setq gnus-secondary-select-methods '((nntp "news.newsfan.net")))
;; My version of gnus in my Mac does not handle html messages
;; correctly (the one in the netbook does, I guess it is a different
;; version). The following will chose plaintext every time this is
;; possible.
(setq mm-discouraged-alternatives '("text/html" "text/richtext"))
;; Available SMTP accounts. The format is
;; type of connection - account in the from field - smtp server -
;; port - login name - password. You can leave the password field
;; as NIL and emacs will ask every time
(defvar smtp-accounts
'((ssl "csfreebird@gmail.com" "smtp.gmail.com" 587 "csfreebird@gmail.com" "mypassword")))
;; Now lets configure smtpmail.el with your name and functions to send
;; mail using your smtp accounts by changing the from field
(require 'smtpmail)
(setq send-mail-function 'smtpmail-send-it
message-send-mail-function 'smtpmail-send-it
mail-from-style nil user-full-name "chen shu"
smtpmail-debug-info t smtpmail-debug-verb t)
(defun set-smtp (mech server port user password)
"Set related SMTP variables for supplied parameters."
(setq smtpmail-smtp-server server smtpmail-smtp-service port
smtpmail-auth-credentials (list (list server port user password)) smtpmail-auth-supported (list mech) smtpmail-starttls-credentials nil)
(message "Setting SMTP server to `%s:%s' for user `%s'." server port user))
(defun set-smtp-ssl (server port user password &optional key cert)
"Set related SMTP and SSL variables for supplied parameters."
(setq starttls-use-gnutls t
starttls-gnutls-program "gnutls-cli"
starttls-extra-arguments nil smtpmail-smtp-server server
smtpmail-smtp-service port
smtpmail-auth-credentials (list (list server port user password)) smtpmail-starttls-credentials (list (list server port key cert)))
(message "Setting SMTP server to `%s:%s' for user `%s'. (SSL enabled.)" server port user))
(defun change-smtp ()
"Change the SMTP server according to the current from line."
(save-excursion
(loop with from = (save-restriction
(message-narrow-to-headers)
(message-fetch-field "from"))
for (auth-mech address . auth-spec) in smtp-accounts
when (string-match address from) do (cond
((memq auth-mech '(cram-md5 plain login))
(return (apply 'set-smtp (cons auth-mech auth-spec))))
((eql auth-mech 'ssl)
(return (apply 'set-smtp-ssl auth-spec)))
(t (error "Unrecognized SMTP auth. mechanism:`%s'." auth-mech))) finally (error "Cannot infer SMTP information."))))
;; The previous function will complain if you fill the from field with
;; an account not present in smtp-accounts.
(defvar %smtpmail-via-smtp (symbol-function 'smtpmail-via-smtp))
(defun smtpmail-via-smtp (recipient smtpmail-text-buffer)
(with-current-buffer smtpmail-text-buffer
(change-smtp))
(funcall (symbol-value '%smtpmail-via-smtp) recipient
smtpmail-text-buffer))
;; This wraps send mail via smtp mail, to be able to send multiple
;; messages with smtpmail.
我的.authinfo文件:
machine imap.gmail.com login csfreebird@gmail.com password mypassword port 993
好了,现在介绍如何使用。
启动gnus后,shift+6 看到server buffer,选择Gmail服务器,然后会看到Gmail里面的文件夹,Enter键就可以进入并查看email.
F键,可以回复,C-c C-c 发送邮件。
u键订阅,这些和Gnus常规操作一样,注意的是最好订阅Inbox和All Mails,前者是为了从订阅的Inbox进入就会发现已经阅读的邮件很容易识别,便于找到未读邮件。
后者是当光标停留在All Mails上的时候,用G G 可以在Mini buffer实现Query提示,然后输入关键字将进行Email查找。
如果想检查一下有没有新Email,将光标停留在Inbox上,按g键。
Enter键进入查询有时候会看不到一些过去已经阅读的Email,所以可以用C-u space 来查看所有Email。
附件问题:
如果有附件,email正文最后会有一个连接,光标移动到那一行,然后回车,就会提示下载。有时候附件是中文,直接按回车不能保存,需要按o键另存为。
如果发送邮件时要添加附件,按Ctr-c 回车 然后f。
如果Email内容是HTML代码,可以将光标移动到该Email的Summary上,然后按K H,Gnus会将Email保存成HTML文件,然后打开外部浏览器浏览本地的HTML文件。
要发送邮件的话,直接按m即可。
享受生活吧。
原文链接: http://blog.csdn.net/sheismylife/article/details/7191463