免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2122 | 回复: 0
打印 上一主题 下一主题

mutt的实现, mutt+msmtp+getmail配置 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-08-03 23:02 |只看该作者 |倒序浏览
为什么是mutt? 为什么mutt需要那么多其他工具才能完成邮件处理?你应该看看王垠的介绍:
http://www.kreny.com/docs/mutt.htm
本文只杂乱谈一下我的配置经验
先说说~/.muttrc几个基本问题,
1.建立邮箱,mutt的邮箱有两种,一种是单文件(所有邮件放到一个文件里),另一种是mail dir形式,后一种目录形式比较好,推荐使用。
## folder & spool
[color="#0000ff"]set spoolfile = ~/Mail/inbox
[color="#0000ff"]set folder    = ~/Mail
[color="#0000ff"]set tmpdir    = ~/.mutt/tmp
[color="#0000ff"]set mbox_type = Maildir
[color="#0000ff"]set mbox      = +inbox
[color="#0000ff"]set record    = +sent
[color="#0000ff"]set postponed = +postponed
mailboxes \
$MAIL \
=inbox \
=junkmail \
=favorites \
=archive
在mailboxes行里,可以定义自己想建立的邮箱,如favorites, archive, junkmail等。
2.编码问题
# locale
[color="#0000ff"]set charset = UTF-8
[color="#0000ff"]set locale  = zh_CN.UTF-8
# hook charset
charset-hook !UTF-8 gbk
charset-hook [color="#800000"]"^us-ascii$" [color="#800000"]"utf-8"
# send charset
[color="#0000ff"]set send_charset=[color="#800000"]"us-ascii:iso-8859-1:utf-8:gbk"
[color="#0000ff"]set rfc2047_parameters=yes
charset-hook里设置里非utf-8邮件使用gbk查看
3.增加垃圾箱,虽然不是很完善
#trash
folder-hook . [color="#008000"]'macro index d "s$folder/trash\r"'
folder-hook $folder/trash [color="#008000"]'bind index d delete-message'
4.排序
#sort
[color="#0000ff"]set sort = reverse-date
[color="#0000ff"]set sort_aux = threads
5.快捷键,
我是这样设置的
#key binding getmail
macro index    G [color="#800000"]"!~/.getmail/getmail\n"   [color="#800000"]"Invoke getmail"
macro pager    G [color="#800000"]"!~/.getmail/getmail\n"   [color="#800000"]"Invoke getmail"
#enter mailbox
macro index  A  [color="#800000"]"c=archive\r"
macro pager  A  [color="#800000"]"c=archive\r"
macro index  I  [color="#800000"]"c!\n" [color="#800000"]"Go to Inbox"
macro pager  I  [color="#800000"]"c!\n" [color="#800000"]"Go to Inbox"
macro index  F    [color="#800000"]"c=favorites\r"
macro pager  F    [color="#800000"]"c=favorites\r"
macro index  J  [color="#800000"]"c=junkmail\r"
macro pager  J  [color="#800000"]"c=junkmail\r"
前面一部分是收邮件(getmail),快捷键是shift+g,(参见下面getmail配置)
后面一部分是进入各个邮箱的快捷键。
6.多账号发送问题,方法是通过判断来信邮件头来选择,局限是只能在回信时自动选择。
以下是完整的发信部分设置
#send hook
send-hook . [color="#008000"]'my_hdr from:dream7180@gmail.com'
send-hook . [color="#008000"]'set sendmail="/usr/bin/msmtp"'
reply-hook . [color="#008000"]'my_hdr reply-to:dream7180@gmail.com'
send-hook [color="#008000"]'~t .*@163\.com$' 'my_hdr from:dreamawake@163.com'
send-hook [color="#008000"]'~t .*@163\.com$' 'my_hdr reply-to:dreamawake@163.com'
send-hook [color="#008000"]'~t .*@163\.com$' 'set sendmail="/usr/bin/msmtp -a 163"'
reply-hook [color="#008000"]'~t .*@163\.com$' 'my_hdr from:dreamawake@163.com'
reply-hook [color="#008000"]'~t .*@163\.com$' 'my_hdr reply-to:dreamawake@163.com'
reply-hook [color="#008000"]'~t .*@163\.com$' 'set sendmail="/usr/bin/msmtp -a 163"'
前面一段是默认的账号,后面两段是用163账号来发送(后面提到msmtp的配置)。
msmtp的配置:
defaults
tls [color="#0000ff"]on
auth [color="#0000ff"]on
tls_certcheck off
logfile ~/.msmtplog
# Gmail service
account gmail
host smtp.gmail.com
from
dream7180@gmail.com
port 587
user
dream7180@gmail.com
password xxxxxx
# 163 service
account 163
tls off
auth plain
host smtp.163.com
from
dreamawake@163.com
user
dreamawake@163.com
password xxxxxx
# [color="#0000ff"]Set a default account
account default : gmail这里就定义了发送的账号,包括gmail和163
getmail的配置
对多账号来说,getmail比fetchmail配置要复杂,但感觉收邮件的表现getmail比fetchmail要好。
多账号配置,授先建立~/.getmail目录,编写~/.getmail/getmailrc.163文件:
[retriever]
type = SimplePOP3Retriever
server = pop.163.com
username =
dreamawake@163.com
password = xxxxxx
[destination]
type = Maildir
path = ~/Mail/inbox/
[options]
verbose = 0
delete = [color="#0000ff"]false
message_log = ~/.getmail/getmail.log
诸如此类,编写~/.getmail/getmailrc.gmail文件
[retriever]
type = SimplePOP3SSLRetriever
server = pop.gmail.com
port = 995
username =
dream7180@gmail.com
password = xxxxxx
[destination]
type = Maildir
path = ~/Mail/inbox/
[options]
verbose = 0
delete = [color="#0000ff"]false
message_log = ~/.getmail/getmail.log
你可以写更多.....
然后是~/.getmail/getmail文件
#!/bin/bash
#getmail [color="#0000ff"]for dream
getmail -v -n -r ~/.getmail/getmailrc.sina -r ~/.getmail/getmailrc.163 -r ~/.getmail/getmailrc.gmail
注意把它设为可运行(+x)。
于是有了上面.muttrc里快捷键收邮件那部分配置。
附上我完整的~/.muttrc以供参考
#号开头是注释
## user
[color="#0000ff"]set realname = [color="#800000"]"rzli"
## folder & spool
[color="#0000ff"]set spoolfile = ~/Mail/inbox
[color="#0000ff"]set folder    = ~/Mail
[color="#0000ff"]set tmpdir    = ~/.mutt/tmp
[color="#0000ff"]set mbox_type = Maildir
[color="#0000ff"]set mbox      = +inbox
[color="#0000ff"]set record    = +sent
[color="#0000ff"]set postponed = +postponed
mailboxes \
$MAIL \
=inbox \
=junkmail \
=favorites \
=archive
[color="#0000ff"]set move = no
# locale
[color="#0000ff"]set charset = UTF-8
[color="#0000ff"]set locale  = zh_CN.UTF-8
# hook charset
charset-hook !UTF-8 gbk
charset-hook [color="#800000"]"^us-ascii$" [color="#800000"]"utf-8"
# send charset
[color="#0000ff"]set send_charset=[color="#800000"]"us-ascii:iso-8859-1:utf-8:gbk"
[color="#0000ff"]set rfc2047_parameters=yes
#Flag
#  [color="#800000"]" "(空): 表示这封邮件不是给你的,也就是说 [color="#0000ff"]To: 和 Cc: Bcc: 都没有你的地址,
#     很多转发的邮件,未确认的邮件列表邮件,垃圾邮件都有这个特征。
# +: 表示你是收件人([color="#0000ff"]To: 是你的地址之一),而且是唯一的收件人。
# T: 表示你是收件人([color="#0000ff"]To: 包括了你的地址之一),但是你不是唯一的收件人。这是一封群体信件。
# C: 表示你的地址出现在 CC:,但是你不是唯一的被抄送的人。
# F: 表示这封邮件是你发出去的。
# L: 表示这是一封你已经加入的邮件列表寄来的。
#trash
folder-hook . [color="#008000"]'macro index d "s$folder/trash\r"'
folder-hook $folder/trash [color="#008000"]'bind index d delete-message'
# [color="#0000ff"]Set header
ignore headers *
unignore headers from: [color="#0000ff"]to: cc: subject date
[color="#0000ff"]set header=no
# [color="#0000ff"]set index
set index_format="%4C %Z %{%y年%b%d}   %-15.15L (%?l?%4l&%4c?) %s"
#score
#score [color="#800000"]"~N" +4    #新信件
#score [color="#800000"]"~D" -5    #有删除标记
#score [color="#800000"]"~O" +1    #上次没有读
#score [color="#800000"]"~f huiqin" +2    #来自 xxxx
#score [color="#800000"]"~s xxxx" + 3    #主题上有 xxxx
#sort
[color="#0000ff"]set sort = reverse-date
[color="#0000ff"]set sort_aux = threads
#confirm
[color="#0000ff"]set confirmappend = no
# wrap & [color="#0000ff"]stop @ last mail
[color="#0000ff"]set pager_stop = yes
[color="#0000ff"]set smart_wrap = yes
[color="#0000ff"]set pager_index_lines = 5
# message editor
[color="#0000ff"]set editor = [color="#800000"]"vim"
[color="#0000ff"]set fast_reply = yes
[color="#0000ff"]set edit_headers = yes
# ext app [color="#0000ff"]to view attachment
[color="#0000ff"]set mailcap_path=[color="#800000"]"~/.mutt/mailcap"
# wait too see output info [color="#0000ff"]while quit
[color="#0000ff"]set wait_key=yes
#Alias
[color="#0000ff"]set alias_file = ~/.mutt/alias
source ~/.mutt/alias
# Attachment
[color="#0000ff"]set attach_format = [color="#800000"]"%u%D%I %t%4n %T%.40d%> [%.7m/%.10M, %.6e%?C?, %C?, %s] "
[color="#0000ff"]set attach_sep = [color="#800000"]"\n"
[color="#0000ff"]set attach_split = yes
# Color
color hdrdefault black        cyan
color quoted     red          white
color signature  brightblack  white
color indicator  brightwhite  magenta
color attachment black        green
color [color="#0000ff"]error      red          white
color message    blue         white
color search     brightwhite  magenta
color status     brightyellow blue
color tree       red          white
color normal     blue         white
color tilde      green        white
color bold       brightyellow white
color markers    red          white
color index  brightwhite    red ~N
color index  red    default ~O
color index  brightblack    default ~D
mono bold      bold
mono underline underline
mono indicator reverse
#
auto_view text/html
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=:-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# include original content when reply
[color="#0000ff"]set include = yes
# from
[color="#0000ff"]set envelope_from = yes
[color="#0000ff"]set encode_from = yes
#send hook
send-hook . [color="#008000"]'my_hdr from:dream7180@gmail.com'
send-hook . [color="#008000"]'set sendmail="/usr/bin/msmtp"'
reply-hook . [color="#008000"]'my_hdr reply-to:dream7180@gmail.com'
send-hook [color="#008000"]'~t .*@163\.com$' 'my_hdr from:dreamawake@163.com'
send-hook [color="#008000"]'~t .*@163\.com$' 'my_hdr reply-to:dreamawake@163.com'
send-hook [color="#008000"]'~t .*@163\.com$' 'set sendmail="/usr/bin/msmtp -a 163"'
reply-hook [color="#008000"]'~t .*@163\.com$' 'my_hdr from:dreamawake@163.com'
reply-hook [color="#008000"]'~t .*@163\.com$' 'my_hdr reply-to:dreamawake@163.com'
reply-hook [color="#008000"]'~t .*@163\.com$' 'set sendmail="/usr/bin/msmtp -a 163"'
#key binding getmail
macro index    G [color="#800000"]"!~/.getmail/getmail\n"   [color="#800000"]"Invoke getmail"
macro pager    G [color="#800000"]"!~/.getmail/getmail\n"   [color="#800000"]"Invoke getmail"
#enter mailbox
macro index  A  [color="#800000"]"c=archive\r"
macro pager  A  [color="#800000"]"c=archive\r"
macro index  I  [color="#800000"]"c!\n" [color="#800000"]"Go to Inbox"
macro pager  I  [color="#800000"]"c!\n" [color="#800000"]"Go to Inbox"
macro index  F    [color="#800000"]"c=favorites\r"
macro pager  F    [color="#800000"]"c=favorites\r"
macro index  J  [color="#800000"]"c=junkmail\r"
macro pager  J  [color="#800000"]"c=junkmail\r"
#[color="#0000ff"]End of muttrc, but it could be more [color="#0000ff"]and more [color="#0000ff"]and more:)
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/24647/showart_1102536.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP