– Outlook(win)->Foxmail(win)->Dreammail(win)->Evolution(linux)->mutt+msmtp+getmail(linux)
上面是我用电子邮件客户端的历程。至于为什么是这样,为什么到了最后居然选择了命令行界面的mutt,不了解Linux好处的人是不会理解的,但是我仍然不想多说,因为我不想把这篇文章变成Linux和CLI的赞美诗,清华大牛人王垠写过一篇《Mutt email 程序使用入门》,讲得比较详细,以下只是我对mutt+msmtp+getmail配置的笔记。
– mutt是邮件管理程序,msmtp是smtp发信程序,getmail是pop收信程序,使用vim编辑邮件,使用wvware把附件中的doc文档转换成html格式查看,使用lynx处理html邮件。发信程序还有一个更强大的叫postfix,但是由于太强大了,一般人用不着它的大部分功能,所以这里使用适合个人用户的msmtp.收信的程度最有名的当数fetchmail,但是似乎fetchmail有一些问题,所以有个牛人就写了getmail来代替它。如果要实现像Gmail标签那样的功能,即对收到的邮件分门别类,还需要使用一个叫procmail的程序,但是我用不着,这里不介绍。
– 以Ubuntu为例,首先安装需要的程序:
–
sudo apt-get install mutt msmtp getmail4 wv lynx
建立邮件箱:
mkdir ~/Mail
mkdir -m 700 ~/Mail/inbox/{,tmp,new,cur}
cd ~/Mail
vim sent
vim postponed
vim inboxrc
以上三个vim命令建立三个文件,里面不要输入内容,打开后直接保存导出即可。
– 配置mutt:
–
vim ~/.muttrc
在其中加入以下内容(复制后粘贴,其中有些东西要自己设置,我在上面加了带有【】的中文注释):
#
# System configuration file for Mutt
#
#
# default list of header fields to weed when displaying
#
ignore “from ” received content- mime-version status x-status message-id
ignore sender references return-path lines
ignore date delivered-to precedence errors-to in-reply-to user-agent
ignore x-loop x-sender x-mailer x-msmail-priority x-mimeole x-ms- x-priority
ignore x-accept-language x-authentication-warning thread- priority importance
ignore x-original-to domainkey-signature dkim-signature
#
# emacs-like bindings
bind editor “\e<delete>” kill-word
bind editor “\e<backspace>” kill-word
#
# map delete-char to a sane value
bind editor <delete> delete-char
#
# some people actually like these settings
#set pager_stop
#bind pager <up> previous-line
#bind pager <down> next-line
#
# don’t add the hostname to the From header
unset use_domain
# don’t generate a From header
unset use_from
#
# Specifies how to sort messages in the index menu.
set sort=threads
#
# Exim does not remove Bcc headers
unset write_bcc
# Postfix and qmail use Delivered-To for detecting loops
unset bounce_delivered
#
# weed out binary-only announcements to -devel-changes
#macro index \CW T!~s\(.*source.*\)\nWn^T~A\n “Weed out binary-only announcements”
#
# imitate the old search-body function
macro index \eb “<search>~b ” “search in message bodies”
#
# simulate the old url menu
macro index,pager \cb “<pipe-message> urlview<Enter>” “call urlview to extract URLs out of a message”
macro attach,compose \cb “<pipe-entry> urlview<Enter>” “call urlview to extract URLs out of a message”
#
# Show documentation when pressing F1
macro generic <f1> “!zcat /usr/share/doc/mutt/manual.txt.gz | sensible-pager\n” “Show Mutt documentation”
macro index <f1> “!zcat /usr/share/doc/mutt/manual.txt.gz | sensible-pager\n” “Show Mutt documentation”
macro pager <f1> “!zcat /usr/share/doc/mutt/manual.txt.gz | sensible-pager\n” “Show Mutt documentation”
#
# Use folders which match on \\.gz$ or \\.bz2$ as [gb]zipped folders:
open-hook \\.gz$ “gzip -cd %f > %t”
close-hook \\.gz$ “gzip -c %t > %f”
append-hook \\.gz$ “gzip -c %t >> %f”
open-hook \\.bz2$ “bzip2 -cd %f > %t”
close-hook \\.bz2$ “bzip2 -c %t > %f”
append-hook \\.bz2$ “bzip2 -c %t >> %f”
#
# show the incoming mailboxes list (just like “mutt -y”) and back when pressing “y”
macro index,pager y “<change-folder>?<toggle-mailboxes>” “show incoming mailboxes list”
bind browser y exit
#
# If Mutt is unable to determine your site’s domain name correctly, you can
# set the default here.
#
# set hostname=cs.hmc.edu
#
# If your sendmail supports the -B8BITMIME flag, enable the following
#
# set use_8bitmime
#
##
## *** DEFAULT SETTINGS FOR THE ATTACHMENTS PATCH ***
##
#
##
## Please see the manual (section “attachments”) for detailed
## documentation of the “attachments” command.
##
## Removing a pattern from a list removes that pattern literally. It
## does not remove any type matching the pattern.
##
## attachments +A */.*
## attachments +A image/jpeg
## unattachments +A */.*
##
## This leaves “attached” image/jpeg files on the allowed attachments
## list. It does not remove all items, as you might expect, because the
## second */.* is not a matching expression at this time.
##
## Remember: “unattachments” only undoes what “attachments” has done!
## It does not trigger any matching on actual messages.
#
## Qualify any MIME part with an “attachment” disposition, EXCEPT for
## text/x-vcard and application/pgp parts. (PGP parts are already known
## to mutt, and can be searched for with ~g, ~G, and ~k.)
##
## I’ve added x-pkcs7 to this, since it functions (for S/MIME)
## analogously to PGP signature attachments. S/MIME isn’t supported
## in a stock mutt build, but we can still treat it specially here.
##
attachments +A */.*
attachments -A text/x-vcard application/pgp.*
attachments -A application/x-pkcs7-.*
#
## Discount all MIME parts with an “inline” disposition, unless they’re
## text/plain. (Why inline a text/plain part unless it’s external to the
## message flow?)
##
attachments +I text/plain
#
## These two lines make Mutt qualify MIME containers. (So, for example,
## a message/rfc822 forward will count as an attachment.) The first
## line is unnecessary if you already have “attach-allow */.*”, of
## course. These are off by default! The MIME elements contained
## within a message/* or multipart/* are still examined, even if the
## containers themseves don’t qualify.
##
#attachments +A message/.* multipart/.*
#attachments +I message/.* multipart/.*
#
## You probably don’t really care to know about deleted attachments.
attachments -A message/external-body
attachments -I message/external-body
#
# colors
color normal white black
color attachment brightyellow black
color hdrdefault cyan black
color indicator black cyan
color markers brightred black
color quoted green black
color signature cyan black
color status brightgreen blue
color tilde blue black
color tree red black
#color header brightgreen black ^From:
#color header brightcyan black ^To:
#color header brightcyan black ^Reply-To:
#color header brightcyan black ^Cc:
#color header brightblue black ^Subject:
#color body brightred black [\-\.+_a-zA-Z0-9]+@[\-\.a-zA-Z0-9]+
#color body brightblue black (https?|ftp)://[\-\.,/%~_:?&=\#a-zA-Z0-9]+
#
# GnuPG configuration
set pgp_decode_command=”gpg –status-fd=2 %?p?–passphrase-fd 0? –no-verbose –quiet –batch –output – %f”
set pgp_verify_command=”gpg –status-fd=2 –no-verbose –quiet –batch –output – –verify %s %f”
set pgp_decrypt_command=”gpg –status-fd=2 %?p?–passphrase-fd 0? –no-verbose –quiet –batch –output – %f”
set pgp_sign_command=”gpg –no-verbose –batch –quiet –output – %?p?–passphrase-fd 0? –armor –detach-sign –textmode %?a?-u %a? %f”
set pgp_clearsign_command=”gpg –no-verbose –batch –quiet –output – %?p?–passphrase-fd 0? –armor –textmode –clearsign %?a?-u %a? %f”
set pgp_encrypt_only_command=”/usr/lib/mutt/pgpewrap gpg –batch –quiet –no-verbose –output – –encrypt –textmode –armor –always-trust — -r %r — %f”
set pgp_encrypt_sign_command=”/usr/lib/mutt/pgpewrap gpg %?p?–passphrase-fd 0? –batch –quiet –no-verbose –textmode –output – –encrypt –sign %?a?-u %a? –armor –always-trust — -r %r — %f”
set pgp_import_command=”gpg –no-verbose –import %f”
set pgp_export_command=”gpg –no-verbose –export –armor %r”
set pgp_verify_key_command=”gpg –verbose –batch –fingerprint –check-sigs %r”
set pgp_list_pubring_command=”gpg –no-verbose –batch –quiet –with-colons –list-keys %r”
set pgp_list_secring_command=”gpg –no-verbose –batch –quiet –with-colons –list-secret-keys %r”
set pgp_good_sign=”^\\[GNUPG:\\] GOODSIG”
#
# S/MIME configuration
set smime_ca_location=”~/.smime/ca-bundle.crt”
set smime_certificates=”~/.smime/certificates”
set smime_keys=”~/.smime/keys”
set smime_pk7out_command=”openssl smime -verify -in %f -noverify -pk7out”
set smime_get_cert_command=”openssl pkcs7 -print_certs -in %f”
set smime_get_signer_cert_command=”openssl smime -verify -in %f -noverify -signer %c -out /dev/null”
set smime_get_cert_email_command=”openssl x509 -in %f -noout -email”
set smime_import_cert_command=”smime_keys add_cert %f”
set smime_encrypt_command=”openssl smime -encrypt %a -outform DER -in %f %c”
set smime_sign_command=”openssl smime -sign -signer %c -inkey %k -passin stdin -in %f -certfile %i -outform DER”
# This alternative command does not include the full certificates chain.
# Be sure to understand RFC 2315 section 9.1 before using it.
# set smime_sign_command=”openssl smime -sign -signer %c -inkey %k -passin stdin -in %f -outform DER”
set smime_decrypt_command=”openssl smime -decrypt -passin stdin -inform DER -in %f -inkey %k -recip %c”
set smime_verify_command=”openssl smime -verify -inform DER -in %s %C -content %f”
set smime_verify_opaque_command=”openssl smime -verify -inform DER -in %s %C”
#
set mixmaster=”mixmaster-filter”
#
# See /usr/share/doc/mutt/README.Debian for details.
source /usr/lib/mutt/source-muttrc.d|
#
#以下是自定义项
#
#收信设置,使用fetchmail收信的时候将下面注释符号去掉半作相应修改,本次使用getmail故此处保持注释状态
#set pop_last=yes
#set pop_pass=【相应Gmail邮箱密码】
#set pop_user=【邮箱账号】@gmail.com
#set pop_host=pops://pop.gmail.com
#
#颜色设置
color normal brightblue default
color attachment blue default
color error red white
color status white blue
color hdrdefault magenta default
color indicator black cyan
#
#发信设置
set sendmail=”/usr/bin/msmtp”
set use_from=yes
set from= 【邮箱账号】@gmail.com
set envelope_from=yes
#
#设置默认编辑器
set editor=”vim”
#设置信箱
set mbox=”~/Mail/inbox”
set mbox_type=maildir
set spoolfile=”~/Mail/inboxrc”
set postponed=”~/Mail/postponed”
set record=”~/Mail/sent”
#
macro index G “!getmail\n” “Invoke getmail”
macro pager G “!getmail\n” “Invoke getmail”
#
# 让mutt监视下面几个邮箱,并随时报告新邮件
# mailboxes “=inbox”
# mailboxes “=USTCstudent”
# mailboxes “=USTCteacher”
# mailboxes “=ustcbbs
# mailboxes “=Gmail”
# set check_new = yes
# set timeout = 600
#
#set alternates=” usr@gmail.com”
## 这是一个格式字符串,用来控制你的index的列表显示。它的缺省定义是
## set index_format=”%4C %Z %{%b %d} %-15.15L (%4l) %s”
##指定你有哪 些信箱文件。当你按 “c” 切换信箱时,再按 Tab 键,这些信箱就可供你选择
mailboxes Mailbox sent-mail
## 这是一个 bool 型变量。它表明你在回信时引用原文是否加入原文的邮件头。
set header=no
## 可以设置为 yes, no, ask-yes, 或者 ask-no.
## 这是说,当你按q退出时,是否提示你(ask-yes,ask-no),
## 还是直接就退出了(yes),还是根本不理你(no)。
#set quit=ask-yes
## 那些类型的附件是允许直接通过 .mailcap 浏览的?
#doc类型的附件通过wvware转成html 浏览
auto_view text/html application/msword
## 这也是一个提示性变量。它是确定当你退出时,是否提示你把信件
##从spool 移动到的mbox 文件。
set move=no
## 当 Mutt 用 thread 方式显示时,是否用纯 ascii 表示树状列表。
set ascii_chars=yes
## 回信时是否包含原文。
set include
## 回信的引文之前插入那个符号?
set indent_str=”> ”
## 设置你自己的邮件头。
my_hdr From: 【邮箱账号】@gmail.com
## 打分
## 新信件+4分,主题包含”通知”的+2,主题包含 “Circulation” +3, 已经标记
## 删除的 -5,上次没有读的 +1,包含 “believe”的 -10(垃圾广告!)。
score “~N” +4
score “~s 通知” +2
score “~s Circulation” +3
score “~D” -5
score “~O” +1
score “~s believe” -10
## 排序方式。
set sort=score
## 当用 thread 排序方式时,我们对各个 thread 的相对排序顺序。
set sort_aux=date
## 如果翻到最后,再按往下翻也不会翻到下一封信件
set pager_stop
## 如果设置,当你按 “r”
## 回信时,就不会再提示你输入回信地址和主题,直接进入编辑
##模式。
set fast_reply
## 当你按 “t” 或者 “D” 之类的标记操作时,是否自动把光标移动到下一封信件。
set resolve=yes
## 地址簿
source ~/.mutt.alias
## 当你在 index 里按 “a”
## 为来信者取别名时,使用哪一个别名文件保存这个别名。
set alias_file=/home/lans/.mutt.alias
## 你发出的邮件保存到那个信箱文件?比如可以像我这样每个月发出的信件放在不同的文件
#里。
set record=”~/Mail/=sent-mail-`date +%Y-%m`”
## 你的终端支持哪一种编码的显示?这个必须和你的终端编码一样。
##注意这个如果设置不正确的话会导致在写邮件时出现一个”bad IDN”的错误信息
set charset=”utf-8″
## send_charset
set send_charset=”gb2312:utf-8:us-ascii:iso-8859-1″
## 外部程序退出时,是否要求用户按一个键才返回。这在察看某些shell命令输出时是比要>的,
## 否则它们一下就消失了。
set wait_key=yes
## 当你要把信件存到另一个信箱,而这个信箱已经存在时,是否提示附加?
set noconfirmappend
## 是否把邮件头也放在编辑器里可以修改?
set edit_headers=no
## 当你在用 pager 看信件时,在 index 留出多少行显示邮件列表?
set pager_index_lines=4
## 告诉 Mutt 你已经订阅了那些邮件列表(mailing-list).
## subscribe fvwm@fvwm.org
## mutt显示日期为中文
set locale=”zh_CN”
## Chinaren 等服务器发出来的信件使用了 quoted-printable 的 subject,
## 而且设置编码为 “iso8859-1″,这显然是错误的。
## 对付这个错误的办法是把 iso-8859-1 变成 gb2312 的别名
charset-hook ^iso-8859-1$ gb2312
## evolution 发过来的 subject 为 utf-8 编码的邮件标题乱码!
## 那就把不是 utf-8 的编码都映射到 gb2312
charset-hook !utf-8 gb2312
– 配置msmtp
–
cd ~
vim .msmtprc
加入以下内容:
defaults
tls on
account gmail
host smtp.gmail.com
from 【邮箱账号】@gmail.com
auth on
user 【邮箱账号】@gmail.com
password 【邮箱密码】
port 587
account default : gmail
– 配置getmail
–
mkdir ~/.getmail
cd ~/.getmail
vim getmailrc
加入以下内容:
[retriever]
type = SimplePOP3SSLRetriever
server = pop.gmail.com
port = 995
username = 【邮箱账号】@gmail.com
password = 【邮箱密码】
#
[destination]
type = Maildir
path = ~/Mail/inbox/
#
[options]
verbose = 0
delete = true
message_log = ~/.getmail/getmail.log
– 设置html邮件、doc附件的处理:
–
cd ~
vim .mailcap
加入以下内容:
application/msword; wvHtml –charset=gb2312 %s – | lynx –dump -stdin;nametemplate=%s.html; copiousoutput
text/html; lynx –dump %s; nametemplate=%s.html; copiousoutput
– 修改文件权限:
–
由于上面的几个配置文件中密码和用户名都是明码,如果被别人看到就完了,所以这里设置其权限为只有创建者本人可读写,其它人均不可读写:
cd ~
chmod 600 .muttrc
chmod 600 .msmtprc
cd .getmail
chmod 600 getmailrc
– 使用crontab定时自动收信(非必需,可选):
–
在终端机中输入:
crontab -e
每隔10分钟收一次信,只收未读的信件:
0,10,20,30,40,50 * * * * getmail -n
– mutt使用地址簿
–
用 alias 来实现一个地址簿。alias 命令的形式是这样的,举个例子:
alias ab Xx X <xxx@mail.ustc.edu.cn>
alias 是命令,ab 是别名,XxX <xxx@mail.ustc.edu.cn> 是一个标准 的 email 地址。这样,如果你在 index 里按 “m”,在 To: 的提示下输入 “ab”,就可 以发信给 XxX<xxx@mail.ustc.edu.cn>。
–
在 To: 的提示下按 Tab 就可以显示联系人列表,然后你可以移动光标选择联系人。
–
如果你有很多 alias 要写,最好把它们写到另外一个文件,比如叫 .mutt.alias. 然后 在 .muttrc 里加上:
source ~/.mutt.alias
在里面写诸如
alias music Music <music@ustc.edu.cn>
alias video 科大影视 <video@ustc.edu.cn>
………
–
你还可以设置一个变量:
set alias_file=~/.mutt.alias
这样你在 index 里按 “a”,就可以把来信人加入到这个 alias 文件了。
– 本文参考:
中国科技大学 李雪白 《配置mutt做邮件客户端》
清华大学 王垠 《Mutt email 程序使用入门》