2009-02-27

mutt+fetchmail+procmail+msmtp+vim<=>gmail


走到mutt里的过程
================================================================================
1.在遥远的以前,就听说mutt只是邮件管理工具,要配合使用fetchmail等收邮件、vim等写邮件、sendmail等发邮件
2.但是mutt没有windows版,我必须使用windows又不想在两个系统里转悠,所以放弃
3.听说mutt也可以在windows里用,但需要cygwin;cygwin是什么东西?我来装一个吧
4.什么?!cygwin有一个G,是国外的服务器,下了几天老下不下来?算了算了,我难不成还为漂亮的鼠标配个电脑不成?
5.我用关键字竟然没有在gmail里搜出来一封肯定存在的而且以前一直能用相同关键字搜出来的邮件。
6.gmail打不开。大概是服务器出啥事了。前些日子,google还把所有搜索结果都标为含恶意软件呢。
7.有人的gmail帐号被封了
8.用mutt吧,反正我这里也不担心什么服务器在国外,硬盘也足够大,不在乎放几G东西。
9.进入下载配置流程。


*****我的信息
我在系统中的用户名:worker
我的 $HOME目录  :/home/worker
我的 Gmail帐号  :GMAILUSER
我的 Gmail密码  :MYPASSWORD


Gmail证书
================================================================================
0.话说
既然知道mutt要配合fetchmail等使用,自然是先配fetchmail;配到一半发现gmail因为是SSL连接,所以要先有证书。好吧,配证书;当然还是靠google大神。
1.跳到个人主目录

$cd ~

2.生成.certs目录

$mkdir .certs

3.取得gmail的cert文件

$openssl s_client -connect smtp.gmail.com:995 -showcerts >.certs/gmail.pem

4.用vim编辑gmail.pem文件
只保留-----BEGIN CERTIFICATE-----到-----END CERTIFICATE-----这段内容(包含这个begin和end行)

$vim .certs/gmail.pem

5.获取证书的Fingerprint

$openssl x509 -fingerprint -md5 -noout -in .certs/gmail.pem >.certs/fingerprint

6.将fingerprint文件中的内容复制到gmail.pem文件头

$vim .certs/*

使gmail.pem的内容变成如下样子:

MD5 Fingerprint=44:A8:E9:2C:FB:A9:7E:6D:F9:DB:F3:62:B2:9E:F1:A9
PEM Data:
-----BEGIN CERTIFICATE-----
MIIC3TCCAkagAwIBAgIDCDijMA0GCSqGSIb3DQEBBQUAME4xCzAJBgNVBAYTAlVT
MRAwDgYDVQQKEwdFcXVpZmF4MS0wKwYDVQQLEyRFcXVpZmF4IFNlY3VyZSBDZXJ0
aWZpY2F0ZSBBdXRob3JpdHkwHhcNMDcxMDI1MTc1MzE2WhcNMDkxMjI0MTg1MzE2
WjBoMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMN
TW91bnRhaW4gVmlldzEUMBIGA1UEChMLR29vZ2xlIEluYy4xFjAUBgNVBAMTDXBv
cC5nbWFpbC5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAO03QxerFKZV
8yeomuL4zSl8Pr7hMWnKMMgp/CwhwadeBmL0LQHHbjL/6z/Z59ZQvrztqkwhchA2
APKzUwRVTyn7Shx6vBqk6oFmTqoOLmY6hbq6l8uVdUv0AfbHwio8CnLpK2+nbuFl
flPwx1DH0E3grD8+CrH5SmScfTWbDkcXAgMBAAGjga4wgaswDgYDVR0PAQH/BAQD
AgTwMB0GA1UdDgQWBBTJRG/OFpZt+BV43JM3NshHMjpwazA6BgNVHR8EMzAxMC+g
LaArhilodHRwOi8vY3JsLmdlb3RydXN0LmNvbS9jcmxzL3NlY3VyZWNhLmNybDAf
BgNVHSMEGDAWgBRI5mj5K9KylddH2CMgEE8zmJCf1DAdBgNVHSUEFjAUBggrBgEF
BQcDAQYIKwYBBQUHAwIwDQYJKoZIhvcNAQEFBQADgYEAOKr3mhxtwFCS3J6lbeaf
3KrHKi935BZkI75sRbON+hog0t2ovcM2i7fxs3xneH8USLsHgfxNBj9tkMogMK/K
sO/NUVZ/IfyqcNNkp2619qTQXthKRH42JKpAKgNhT1bdno3pxn+eDEpqmU3CE7IP
HDCjWOK1fGkZ/yFAuTxuxAc=
-----END CERTIFICATE-----

7.在.certs目录下新建文件equifax.pem,添加以下内容:

MD5 Fingerprint: 67:CB:9D:C0:13:24:8A:82:9B:B2:17:1E:D1:1B:EC:D4
PEM Data:
-----BEGIN CERTIFICATE-----
MIIDIDCC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r87yloqaKHee9570+sB3c4
-----END CERTIFICATE-----

8.rehash以上两个文件

$c_rehash .certs

9.检查CA文件

$openssl s_client -connect pop.gmail.com:995 -CApath .certs/

如果看到返回结果中有“Verify return code: 0 (ok)”,则CA文件是好的.



******中间碰到的问题点
别人都说执行openssl之后,把begin到end的内容copy到文件里保存;
可我不知道怎么从命令窗口里copy东西,只能先把输出结果重定向到文件,再把不需要的内容删掉。
反正最终结果一样么,办法傻就傻点吧


fetchmail配置
================================================================================
0.返回过来配fetchmail
1.在/home/worker/下新建.fetchmailrc文件并编辑

$vim .fetchmailrc

添加以下内容

defaults
  protocol POP3
  mda "formail -s procmail"
  antispam -1
  keep
  ssl sslcertck keep
     sslcertpath '/home/worker/.certs'
poll pop.gmail.com with uidl
    user 'GMAILUSER@gmail.com' there with password 'MYPASSWORD' is 'worker' here
    mda "/usr/bin/procmail -d %T"

2.在C:\WINDOWS\system32\drivers\etc\services文件末尾添加下面这行内容
(不加就会报错:errors on getaddrinfo(): nodename nor servname provided, or not known )

pop3s 995/tcp #POP3 SSL

3.修改.fetchmailrc权限

chmod 710 .fetchmailrc

4.测试当前配置是否可用

$fetchmail -c

我的输出结果是

2 messages for GMAILUSER@gmail.com at pop.gmail.com(2721 octets).

表示fetchmail总算配置成功啦



******中间碰到的问题点
那句密码配置语句好口语化啊,我都不敢相信这真的是配置文件


procmail配置
================================================================================
0.真的开始配了,才知道在fetchmail获取邮件和mutt管理邮件之间还有一道procmail分拣邮件的过程。
1.在.bashrc文件中添加下面内容,用来为所有的应用程序指明邮件的投递点
(当然,如果/var/spool/mail目录不存在的话,就新建之)

# Set the MAIL
export MAIL=/var/spool/mail/worker

2.新建.procmailrc文件,添加如下内容

PATH=/bin:/usr/bin:/usr/local/bin
VERBOSE=off
DEFAULT=/var/spool/mail/worker
MAILDIR=$HOME/mail
LOGFILE=$HOME/.procmaillog
# Recipes below this comment:
:0:
* ^TOmutt-user
mutt

3.修改.procmailrc文件权限

$chmod 640 .procmailrc

4.收邮件吧
(收到前面check到的两封邮件了)

$fetchmail

5.查看邮件吧

$mutt

哈哈,看到这两封邮件了,OK,总算折腾到这里了。看到成果才觉得折腾有劲头。

msmtp配置
================================================================================
0.据说mutt的配置很繁琐的,那先不管,先来配个发邮件的;又据说sendmail配置也很繁琐的,那我换个msmtp。
1.跟fetchmail一样,也需要创建证书:新建tls.pem文件:

$vim .certs/tls.pem

添加内容如下:

-----BEGIN CERTIFICATE-----
MIIDJzCCApCgAwIBAgIBATANBgkqhkiG9w0BAQQFADCBzjELMAkGA1UEBhMCWkExFTATBgNVBAgT
DFdlc3Rlcm4gQ2FwZTESMBAGA1UEBxMJQ2FwZSBUb3duMR0wGwYDVQQKExRUaGF3dGUgQ29uc3Vs
dGluZyBjYzEoMCYGA1UECxMfQ2VydGlmaWNhdGlvbiBTZXJ2aWNlcyBEaXZpc2lvbjEhMB8GA1UE
AxMYVGhhd3RlIFByZW1pdW0gU2VydmVyIENBMSgwJgYJKoZIhvcNAQkBFhlwcmVtaXVtLXNlcnZl
ckB0aGF3dGUuY29tMB4XDTk2MDgwMTAwMDAwMFoXDTIwMTIzMTIzNTk1OVowgc4xCzAJBgNVBAYT
AlpBMRUwEwYDVQQIEwxXZXN0ZXJuIENhcGUxEjAQBgNVBAcTCUNhcGUgVG93bjEdMBsGA1UEChMU
VGhhd3RlIENvbnN1bHRpbmcgY2MxKDAmBgNVBAsTH0NlcnRpZmljYXRpb24gU2VydmljZXMgRGl2
aXNpb24xITAfBgNVBAMTGFRoYXd0ZSBQcmVtaXVtIFNlcnZlciBDQTEoMCYGCSqGSIb3DQEJARYZ
cHJlbWl1bS1zZXJ2ZXJAdGhhd3RlLmNvbTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA0jY2
aovXwlue2oFBYo847kkEVdbQ7xwblRZH7xhINTpS9CtqBo87L+pW46+GjZ4X9560ZXUCTe/LCaIh
Udib0GfQug2SBhRz1JPLlyoAnFxODLz6FVL88kRu2hFKbgifLy3j+ao6hnO2RlNYyIkFvYMRuHM/
qgeN9EJN50CdHDcCAwEAAaMTMBEwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQQFAAOBgQAm
SCwWwlj66BZ0DKqqX1Q/8tfJeGBeXm43YyJ3Nn6yF8Q0ufUIhfzJATj/Tb7yFkJD57taRvvBxhEf
8UqwKEbJw8RCfbz6q1lu1bdRiBHjpIUZa4JMpAwSremkrj/xw0llmozFyD4lt5SZu5IycQfwhl7t
UCemDaYj+bvLpgcUQg==
-----END CERTIFICATE-----

2.新建.msmtprc文件,内容如下

account default
host smtp.gmail.com
port 587
from GMAILUSER@gmail.com
tls on
tls_starttls on
tls_trust_file /home/worker/.certs/tls.pem
auth on
user GMAILUSER
password MYPASSWORD
protocol smtp
logfile ~/.msmtp.log

2.修改文件权限

$chmod 600 .msmtprc




******中间碰到的问题点
起先没有意识到TLS证书不是SSL证书,.msmtprc文件里写的是SSL证书的文件名;
发邮件的时候怎么也发不了,后来才突然发应过来


mutt配置
================================================================================
0.实际上是网上直接下载的
1.新建.muttrc文件,添加内容如下

#======================================================#
# Boring details
set realname = "GMAIL USERNAME"
set from = "GMAILUSER@gmail.com"
set use_from = yes
set envelope_from ="yes"

# Use a signature
#set signature="~/.signature"

# Use msmtp rather than sendmail. Check that
# the path is correct for your system:
set sendmail="/usr/sbin/msmtp"

# If not set in ~/.bashrc:
set spoolfile = /var/spool/mail/worker

#======================================================#
# Folders
set folder="$HOME/mail" # Local mailboxes stored here
set record="+sent" # Where to store sent messages
set postponed="+postponed" # Where to store draft messages
set mbox_type=mbox # Mailbox type
set move=no # Don't move mail from spool

#======================================================#
# Watch these mailboxes for new mail, useful only if
# Procmail or Maildrop is used to sort mail.
mailboxes ! +slrn +fetchmail +mutt
#set sort_browser=alpha # Sort mailboxes by alpha(bet)
set sort_browser=date # Sort mailboxes by date(LATEST first)

#======================================================#
# What to show and order of headers
ignore *
unignore Date: From: User-Agent: X-Mailer X-Operating-System To: \
Cc: Reply-To: Subject: Mail-Followup-To:
hdr_order Date: From: User-Agent: X-Mailer X-Operating-System To: \
Cc: Reply-To: Subject: Mail-Followup-To:

#======================================================#
# which editor do you want to use?
# vim of course!
set editor="vim -c 'set tw=72 et' '+/^$' "
set edit_headers=yes # See the headers when editing

#======================================================#
# Aliases

#set alias_file = ~/mail/mutt_aliases # In their own file
#source ~/mail/mutt_aliases # Source them
#set sort_alias=alias # Sort alphabetically

#======================================================#
# Colours: defaults are a little bleak so experiment!

#source ~/.mutt/mutt_colors # In their own file

#======================================================#
# Lists: An example using the mutt-users list:

lists mutt-users
subscribe mutt-users
set followup_to=yes # Sets 'Mail-Followup-To' header
set honor_followup_to=yes
fcc-hook mutt-user +mutt # See your own posts using fcc

#======================================================#
# Odds and ends

set markers # mark wrapped lines of text in the pager with a +
set smart_wrap # Don't wrap mid-word
set pager_context=5 # Retain 5 lines of previous page when scrolling.
set status_on_top # Status bar on top.
push <show-version> # Shows mutt version at startup

#======================================================#
# add following lines
set sort = 'threads'
set sort_aux = 'last-date-received'
#set imap_check_subscribed

ignore "Authorication-Results:"
ignore "DomainKey-Signature:"
ignore "DKIM-Signature:"
hdr_order Date From To Cc

2.再试一下发邮件,也成功了。



******中间碰到的问题点
在进行发送邮件配置的时候碰到了不少问题,于是反复google
中间,看到有人问发不了邮件是哪里配错了,大家热心提供了种种可能性,最后他发现是自己没装msmtp,我晕。
后来我就想难不成我也没装?检查了一下,装了是装了。
再检查,原来不是这个配置下载下来的时候写着的“/usr/bin/msmtp”,而是“usr/sbin/msmtp”


总结
================================================================================
网上提供了很多配置手顺,很多都是很详细的。
但是每台机器总归有点不一样的情况,所以碰到问题是在所难免的,细心Google就好

比较那个什么的是,虽然配成功了,能收能发了,但我对配置文件中的很多东西都还是不甚清楚的~
以后使用过程中,再慢慢配mutt了。

接下来要搞定的是中日文同时显示的问题,还有家里那台机器上Vim的诡异表现

没有评论:

发表评论