mutt的實現, mutt+msmtp+getmail配置

爲什麼是mutt? 爲什麼mutt需要那麼多其他工具才能完成郵件處理?你應該看看王垠的介紹:
[url]http://www.kreny.com/docs/mutt.htm[/url]
本文只雜亂談一下我的配置經驗
先說說~/.muttrc幾個基本問題,
1.建立郵箱,mutt的郵箱有兩種,一種是單文件(所有郵件放到一個文件裏),另一種是mail dir形式,後一種目錄形式比較好,推薦使用。

## folder & spool
set spoolfile = ~/Mail/inbox
set folder    = ~/Mail
set tmpdir    = ~/.mutt/tmp

set mbox_type = Maildir
set mbox      = +inbox
set record    = +sent
set postponed = +postponed

mailboxes \
$MAIL \
=inbox \
=junkmail \
=favorites \
=archive

在mailboxes行裏,可以定義自己想建立的郵箱,如favorites, archive, junkmail等。

2.編碼問題

# locale
set charset = UTF-8
set locale  = zh_CN.UTF-8
# hook charset
charset-hook !UTF-8 gbk
charset-hook "^us-ascii$" "utf-8"
# send charset
set send_charset="us-ascii:iso-8859-1:utf-8:gbk"
set rfc2047_parameters=yes

charset-hook裏設置裏非utf-8郵件使用gbk查看

3.增加垃圾箱,雖然不是很完善
#trash
folder-hook . 'macro index d "s$folder/trash\r"'
folder-hook $folder/trash 'bind index d delete-message'

4.排序
#sort
set sort = reverse-date
set sort_aux = threads

5.快捷鍵,
我是這樣設置的
#key binding getmail
macro index    G "!~/.getmail/getmail\n"   "Invoke getmail"
macro pager    G "!~/.getmail/getmail\n"   "Invoke getmail"

#enter mailbox
macro index  A  "c=archive\r"
macro pager  A  "c=archive\r"
macro index  I  "c!\n" "Go to Inbox"
macro pager  I  "c!\n" "Go to Inbox"
macro index  F    "c=favorites\r"
macro pager  F    "c=favorites\r"
macro index  J  "c=junkmail\r"
macro pager  J  "c=junkmail\r"

前面一部分是收郵件(getmail),快捷鍵是shift+g,(參見下面getmail配置)
後面一部分是進入各個郵箱的快捷鍵。

6.多賬號發送問題,方法是通過判斷來信郵件頭來選擇,侷限是只能在回信時自動選擇。
以下是完整的發信部分設置
#send hook
send-hook . 'my_hdr from:[email protected]'
send-hook . 'set sendmail="/usr/bin/msmtp"'
reply-hook . 'my_hdr reply-to:[email protected]'

send-hook '~t .*@163\.com$' 'my_hdr from:[email protected]'
send-hook '~t .*@163\.com$' 'my_hdr reply-to:[email protected]'
send-hook '~t .*@163\.com$' 'set sendmail="/usr/bin/msmtp -a 163"'

reply-hook '~t .*@163\.com$' 'my_hdr from:[email protected]'
reply-hook '~t .*@163\.com$' 'my_hdr reply-to:[email protected]'
reply-hook '~t .*@163\.com$' 'set sendmail="/usr/bin/msmtp -a 163"'

前面一段是默認的賬號,後面兩段是用163賬號來發送(後面提到msmtp的配置)。

msmtp的配置:
defaults
tls on
auth on
tls_certcheck off
logfile ~/.msmtplog

# Gmail service
account gmail
host smtp.gmail.com
from [email][email protected][/email]
port 587
user [email][email protected][/email]
password xxxxxx

# 163 service
account 163
tls off
auth plain
host smtp.163.com
from [email][email protected][/email]
user [email][email protected][/email]
password xxxxxx

# 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 = [email][email protected][/email]
password = xxxxxx

[destination]
type = Maildir
path = ~/Mail/inbox/

[options]
verbose = 0
delete = false
message_log = ~/.getmail/getmail.log

諸如此類,編寫~/.getmail/getmailrc.gmail文件

[retriever]
type = SimplePOP3SSLRetriever
server = pop.gmail.com
port = 995
username = [email][email protected][/email]
password = xxxxxx

[destination]
type = Maildir
path = ~/Mail/inbox/

[options]
verbose = 0
delete = false
message_log = ~/.getmail/getmail.log

你可以寫更多.....

然後寫一個收郵件的腳本文件~/.getmail/getmail
#!/bin/bash
#getmail for dream
getmail -v -n -r ~/.getmail/getmailrc.sina -r ~/.getmail/getmailrc.163 -r ~/.getmail/getmailrc.gmail
注意把它設爲可運行(+x)。
於是有了上面.muttrc裏快捷鍵收郵件那部分配置。

附上我完整的~/.muttrc以供參考
#號開頭是註釋

## user
set realname = "rzli"

## folder & spool
set spoolfile = ~/Mail/inbox
set folder    = ~/Mail
set tmpdir    = ~/.mutt/tmp

set mbox_type = Maildir
set mbox      = +inbox
set record    = +sent
set postponed = +postponed

mailboxes \
$MAIL \
=inbox \
=junkmail \
=favorites \
=archive

set move = no

# locale
set charset = UTF-8
set locale  = zh_CN.UTF-8
# hook charset
charset-hook !UTF-8 gbk
charset-hook "^us-ascii$" "utf-8"
# send charset
set send_charset="us-ascii:iso-8859-1:utf-8:gbk"
set rfc2047_parameters=yes

#Flag
#  " "(空): 表示這封郵件不是給你的,也就是說 To: 和 Cc: Bcc: 都沒有你的地址,
#     很多轉發的郵件,未確認的郵件列表郵件,垃圾郵件都有這個特徵。
# +: 表示你是收件人(To: 是你的地址之一),而且是唯一的收件人。
# T: 表示你是收件人(To: 包括了你的地址之一),但是你不是唯一的收件人。這是一封羣體信件。
# C: 表示你的地址出現在 CC:,但是你不是唯一的被抄送的人。
# F: 表示這封郵件是你發出去的。
# L: 表示這是一封你已經加入的郵件列表寄來的。

#trash
folder-hook . 'macro index d "s$folder/trash\r"'
folder-hook $folder/trash 'bind index d delete-message'

# Set header
ignore headers *
unignore headers from: to: cc: subject date
set header=no

# set index
set index_format="%4C %Z %{%y年%b%d}   %-15.15L (%?l?%4l&%4c?) %s"

#score
#score "~N" +4    #新信件
#score "~D" -5    #有刪除標記
#score "~O" +1    #上次沒有讀
#score "~f huiqin" +2    #來自 xxxx
#score "~s xxxx" + 3    #主題上有 xxxx

#sort
set sort = reverse-date
set sort_aux = threads

#confirm
set confirmappend = no

# wrap & stop @ last mail
set pager_stop = yes
set smart_wrap = yes
set pager_index_lines = 5

# message editor
set editor = "vim"
set fast_reply = yes
set edit_headers = yes

# ext app to view p_w_upload
set mailcap_path="~/.mutt/mailcap"

# wait too see output info while quit
set wait_key=yes

#Alias
set alias_file = ~/.mutt/alias
source ~/.mutt/alias


# Attachment
set attach_format = "%u%D%I %t%4n %T%.40d%> [%.7m/%.10M, %.6e%?C?, %C?, %s] "
set attach_sep = "\n"
set attach_split = yes

# Color
color hdrdefault black        cyan
color quoted     red          white
color signature  brightblack  white
color indicator  brightwhite  magenta
color p_w_upload black        green
color 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
set include = yes

# from
set envelope_from = yes
set encode_from = yes

#send hook
send-hook . 'my_hdr from:[email protected]'
send-hook . 'set sendmail="/usr/bin/msmtp"'
reply-hook . 'my_hdr reply-to:[email protected]'

send-hook '~t .*@163\.com$' 'my_hdr from:[email protected]'
send-hook '~t .*@163\.com$' 'my_hdr reply-to:[email protected]'
send-hook '~t .*@163\.com$' 'set sendmail="/usr/bin/msmtp -a 163"'

reply-hook '~t .*@163\.com$' 'my_hdr from:[email protected]'
reply-hook '~t .*@163\.com$' 'my_hdr reply-to:[email protected]'
reply-hook '~t .*@163\.com$' 'set sendmail="/usr/bin/msmtp -a 163"'

#key binding getmail
macro index    G "!~/.getmail/getmail\n"   "Invoke getmail"
macro pager    G "!~/.getmail/getmail\n"   "Invoke getmail"

#enter mailbox
macro index  A  "c=archive\r"
macro pager  A  "c=archive\r"
macro index  I  "c!\n" "Go to Inbox"
macro pager  I  "c!\n" "Go to Inbox"
macro index  F    "c=favorites\r"
macro pager  F    "c=favorites\r"
macro index  J  "c=junkmail\r"
macro pager  J  "c=junkmail\r"

#End of muttrc, but it could be more and more and more:)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章