歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> GNU/Linux下Gmail的mutt+msmtp+getmail解決方案

GNU/Linux下Gmail的mutt+msmtp+getmail解決方案

日期:2017/2/28 16:23:03   编辑:Linux教程

- 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=" [email protected]"
## 這是一個格式字符串,用來控制你的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 [email protected]
## 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

Copyright © Linux教程網 All Rights Reserved