<<我的邮件客户端(mutt+getmail+msmtp+procmail)>>
linux-dash
A beautiful web dashboard for Linux
项目地址:https://gitcode.com/gh_mirrors/li/linux-dash

·
<<我的邮件客户端(mutt+getmail+msmtp+procmail)>>
Tags: linux-tool,mail
1. 相关的程序和对应的配置文件
1.1 要用到的程序:
mutt // 邮件管理客户端
getmail // 我们用它来收取邮件
procmail // 用它来对收取到的邮件进行过滤
msmtp // 用它来发送邮件
1.2 相应的配置文件和目录:
~/.getmail/ // getmail(用于收邮件)配置文件目录
~/.Mail/ // 把收取下来的邮件保存到的目录
~/.mailcap // 配置额外程序使得mutt可以查看非纯文本文件
~/.msmtprc // msmtp(用于发送邮件)配置文件
~/.mutt/ // mutt配置文件目录
~/.muttrc // mutt配置文件
~/.procmailrc // procmail(用于过滤收取到的邮件)配置文件
2. 安装必要的程序
这安装过程真不是一般的简单!
2.1 mutt
[~]# yum -y install mutt
2.2 getmail
[~]# yum -y install getmail
2.3 msmtp
[~]# yum -y install msmtp
2.4 procmail
[~]# yum -y install procmail
3. 作一些配置
3.1 getmail
首先我们先对getmail进行配置, 毕竟得先取到邮件才能进行下一步!
1) 新建一个目录 .getmail/ 用来保存getmail的配置文件等
[~]$ cd
[~]$ mkdir .getmail
2) getmailrc
由于 getmail 是从配置文件中读取配置信息, 所以我们得先准备一个配置文件:
3) 试一下
[~]$ /usr/bin/getmail -v -n -r ~/.getmail/getmailrc.nuoerlz.gmail
getmail version 4.20.3
Copyright (C) 1998-2009 Charles Cazabon. Licensed under the GNU GPL version 2.
SimplePOP3SSLRetriever:nuoerlz@gmail.com@pop.gmail.com:995:
msg 1/676 (5804 bytes) delivered
...
如果能出现类似的消息, 则说明getmail已经配置能够成功收取邮件了, 收取下来的邮件
保存在 ~/.Mail/inbox/nuoerlz_gmail/ 目录下.
3.2 mutt
是时候用 mutt 来阅读我们收取下来的邮件了, 在启动 mutt 之前, 同样我们也需要配置
一下:
1) ~/.muttrc
2) 启动mutt
[~]$ mutt
就这么简单! 如果对mutt的各种快捷键不太熟悉的话, 我们可以按下"?"调出帮助.
3.3 procmail
如果你有大量的邮件, 你肯定就会想对收取下来的邮件进行过滤分类, 把一些垃圾文件
扔掉, 把一些重要的文件放到一个专门的邮箱目录... 那么 procmail 就是专门为你设
计的!
1) ~/.procmailrc
对于 procmailrc 文件的语法, 我们可以在网上搜索或"man procmail", 都能找到大量
的文档信息, 这里就不多说了.
2) 对 getmailrc 进行修改
有了 ~/.procmailrc 配置文件, 我们就可以对邮件进行过滤分类了, 但我们还想在收取
邮件的同时就对邮件进行过滤分类, 这我们可以通过对 getmailrc 作一些修改来实现.
修改 [destination] 部分:
3) 再收一次
[~]$ /usr/bin/getmail -v -n -r ~/.getmail/getmailrc.nuoerlz.gmail
3.4 msmtp
到目前, 我们已经能收取并过滤分类邮件了, 但发邮件呢?
linux下发邮件的程序有很多, msmtp就很出色, 配置还简单!
1) ~/.msmtprc
2) 简单地使用一下
[~]$ msmtp xxok@163.com
// 随便输入一些内容用ctrl+d结束. 然后到邮箱看看有没有收到.
3) 在mutt中使用msmtp发邮件
记得, 在 ~/.muttrc 中, 我们写有如下的配置:
send-hook . 'set sendmail="/usr/local/msmtp/bin/msmtp"'
如此, 我们在mutt中发邮件时, 就是通过msmtp来发送了.
4. reference
<<使用mutt+msmtp做linux邮件客户端>>
http://storysky.blog.51cto.com/628458/293005
Procmail入门
http://lifegoo.pluskid.org/wiki/Procmail.html#sec6
Timo's procmail tips and recipes
http://lipas.uwasa.fi/~ts/info/proctips.html
http://dreamland.blog.51cto.com/417830/87510
http://home.ustc.edu.cn/~lixuebai/GNU/MuttConfig.html
man /usr/share/doc/mutt-1.5.21/manual.txt
Tags: linux-tool,mail
1. 相关的程序和对应的配置文件
1.1 要用到的程序:
mutt // 邮件管理客户端
getmail // 我们用它来收取邮件
procmail // 用它来对收取到的邮件进行过滤
msmtp // 用它来发送邮件
1.2 相应的配置文件和目录:
~/.getmail/ // getmail(用于收邮件)配置文件目录
~/.Mail/ // 把收取下来的邮件保存到的目录
~/.mailcap // 配置额外程序使得mutt可以查看非纯文本文件
~/.msmtprc // msmtp(用于发送邮件)配置文件
~/.mutt/ // mutt配置文件目录
~/.muttrc // mutt配置文件
~/.procmailrc // procmail(用于过滤收取到的邮件)配置文件
2. 安装必要的程序
这安装过程真不是一般的简单!
2.1 mutt
[~]# yum -y install mutt
2.2 getmail
[~]# yum -y install getmail
2.3 msmtp
[~]# yum -y install msmtp
2.4 procmail
[~]# yum -y install procmail
3. 作一些配置
3.1 getmail
首先我们先对getmail进行配置, 毕竟得先取到邮件才能进行下一步!
1) 新建一个目录 .getmail/ 用来保存getmail的配置文件等
[~]$ cd
[~]$ mkdir .getmail
2) getmailrc
由于 getmail 是从配置文件中读取配置信息, 所以我们得先准备一个配置文件:
[~]$ vi ~/.getmail/getmailrc.nuoerlz.gmail
[retriever] // 设置为gmail的收件服务器
type = SimplePOP3SSLRetriever
server = pop.gmail.com
port = 995
username = nuoerlz@gmail.com // 用户名
password = xxxxxxx // 用户密码
[destination] // 告诉getmail把收取下来的邮件如何储存等
type = Maildir // 以目录的形式储存
path = ~/.Mail/inbox/nuoerlz.gmail/ // 储存到的目录(若没有须手动创建)
[options] // 一些选项
verbose = 0 // 调试时很有用
delete = false // 在邮箱服务端也保留一份
message_log = ~/.getmail/getmail.gmail.log // ...
// End of getmailrc.nuoerlz.gmail
3) 试一下
[~]$ /usr/bin/getmail -v -n -r ~/.getmail/getmailrc.nuoerlz.gmail
getmail version 4.20.3
Copyright (C) 1998-2009 Charles Cazabon. Licensed under the GNU GPL version 2.
SimplePOP3SSLRetriever:nuoerlz@gmail.com@pop.gmail.com:995:
msg 1/676 (5804 bytes) delivered
...
如果能出现类似的消息, 则说明getmail已经配置能够成功收取邮件了, 收取下来的邮件
保存在 ~/.Mail/inbox/nuoerlz_gmail/ 目录下.
3.2 mutt
是时候用 mutt 来阅读我们收取下来的邮件了, 在启动 mutt 之前, 同样我们也需要配置
一下:
1) ~/.muttrc
[~]$ vi ~/.muttrc
# user
set realname = "erlz.nuo"
# folder & spool
set spoolfile = ~/.Mail/inbox/default/ # 启动mutt默认进入的邮箱
set folder = ~/.Mail # 信箱根目录
set tmpdir = ~/.mutt/tmp #
set mbox_type = Maildir # 设置为目录存储方式
set mbox = +inbox # 设置mbox(~/.Mail/inbox)
set record = +sent # 保存发送后的邮件(~/.Mail/sent)
set postponed = +postponed #
# 退出时不在提示把信件从spool移动到的mbox文件
set move = no
# 当你按q退出时, 是否提示你(ask-yes,ask-no)
set quit=ask-yes
# 快捷键超时时间
set timeout = 600
# locale
set charset = UTF-8
set locale = zh_CN.UTF-8
# hook charset
charset-hook gb2312 gb2312
charset-hook GB2312 GB2312
charset-hook big5 big5
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: 表示这是一封你已经加入的邮件列表寄来的.
set to_chars=" +TCFL"
# 增加垃圾箱, 虽然不是很完善
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 reply-to:
# 回信引文不用包含原文的信头
set header=no
# set index
set index_format="%5C %Z %{%y年%b%d} %-20.20L (%?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 = 'threads'
# 当用 thread 排序方式时, 我们对各个 thread 的相对时间顺序.
set sort_aux = 'reverse-last-date-received'
# don't confirm when appending messages to a mailbox
set confirmappend = no
# 禁止PAGE键切换到下一封信件
set pager_stop = yes
# 当行太长需要折行显示时, 按单词为边界折行, 而不是以屏幕边界为界限.
set smart_wrap = yes
# 当你在用 pager 看信件时, 在 index 留出多少行显示邮件列表?
set pager_index_lines = 5
# message editor
set editor = "vim"
# 快速回复, 不用确认回复地址和主题
set fast_reply = yes
# 是否把邮件头也放在编辑器里可以修改?
set edit_headers = no
# ext app to view attachment
set mailcap_path="~/.mailcap"
# 当外部程序退出时, 是否要求用户按一个键才返回
set wait_key=yes
# alias
set alias_file = ~/.mutt/.mutt.alias
source ~/.mutt/.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
alternative_order text/enriched text/plain text application/postscript image/*
# Colors
#color obj front back
#----- ------------ --------------- ---------
#color hdrdefault black cyan # 邮件头颜色
#color quoted blue white # 引文颜色
#color signature brightblack white
color indicator brightwhite magenta
color attachment black green
#color error red white
#color message blue white
color search black brightyellow
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
# 让mutt可以更好的阅读html邮件
auto_view text/html
#view word
auto_view application/msword
# include original content when reply
set include = yes
# from
set envelope_from = yes
set encode_from = yes
# send hook
##所有我可能会用到的邮箱
send-hook . 'set sendmail="/usr/local/msmtp/bin/msmtp"'
alternates "nuoerlz@gmail.com|tge3636@126.com|lcy3636@126.com"
set from="nuoerlz@gmail.com" # 默认的发信人
set use_from=yes # mutt自动生成from地址
set reply_to=yes # 尽量使用原信中的reply-to, 对邮件列表尤其适用
set reverse_name=yes # 用哪个邮箱收的信, 就用哪个邮箱回信
# key binding
macro index ,gp "c=postponed\r"
macro index ,gp "c=postponed\r"
macro index ,gs "c=sent\r"
macro index ,gs "c=sent\r"
macro index ,gr "c=trash\r"
macro index ,gr "c=trash\r"
macro index,pager ,G "!~/.getmail/getmail\n" "Invoke getmail"
macro index,pager ,ebt ":set from=tge3636@126.com\r:set edit_headers=yes\r:set realname=NuoErlz\r"
macro index,pager ,ebn ":set from=nuoerlz@gmail.com\r:set edit_headers=yes\r:set realname=erlz.nuo\r"
macro index,pager ,ehd ":set edit_headers=yes\r"
macro index,pager ,ehn ":set edit_headers=no\r"
macro index,pager ,gdf "c=inbox/default\r:set from=nuoerlz@gmail.com\r:set edit_headers=no\r:set realname=\"erlz.nuo\"\r"
macro index,pager ,gic "c=inbox/nuoerlz_gmail/list_cpp\r:set from=nuoerlz@gmail.com\r:set edit_headers=no\r:set realname=\"erlz.nuo\"\r"
macro index,pager ,gid "c=inbox/nuoerlz_gmail/default\r:set from=nuoerlz@gmail.com\r:set edit_headers=no\r:set realname=\"erlz.nuo\"\r"
macro index,pager ,gie "c=inbox/nuoerlz_gmail/list_eng\r:set from=nuoerlz@gmail.com\r:set edit_headers=no\r:set realname=\"erlz.nuo\"\r"
macro index,pager ,gif "c=inbox/nuoerlz_gmail/list_fedora\r:set from=nuoerlz@gmail.com\r:set edit_headers=no\r:set realname=\"erlz.nuo\"\r"
macro index,pager ,gig "c=inbox/nuoerlz_gmail/news_G2G\r:set from=nuoerlz@gmail.com\r:set edit_headers=no\r:set realname=\"erlz.nuo\"\r"
macro index,pager ,gij "c=inbox/nuoerlz_gmail/list_joke\r:set from=nuoerlz@gmail.com\r:set edit_headers=no\r:set realname=\"erlz.nuo\"\r"
macro index,pager ,gim "c=inbox/nuoerlz_gmail/list_vim\r:set from=nuoerlz@gmail.com\r:set edit_headers=no\r:set realname=\"erlz.nuo\"\r"
macro index,pager ,gis "c=inbox/nuoerlz_gmail/list_shlug\r:set from=nuoerlz@gmail.com\r:set edit_headers=no\r:set realname=\"erlz.nuo\"\r"
macro index,pager ,giv "c=inbox/nuoerlz_gmail/list_devel\r:set from=nuoerlz@gmail.com\r:set edit_headers=no\r:set realname=\"erlz.nuo\"\r"
macro index,pager ,gld "c=inbox/lcy3636_126/default\r:set from=lcy3636@126.com\r:set edit_headers=no\r:set realname=NuoErlz\r"
macro index,pager ,gtd "c=inbox/tge3636_126/default\r:set from=tge3636@126.com\r:set edit_headers=no\r:set realname=NuoErlz\r"
macro index,pager,generic ,sm ":source $HOME/.muttrc\r"
macro index,pager,generic ,vm "!xterm -bg wheat -e gvim $HOME/.muttrc\r"
## 告诉 Mutt 你已经订阅了那些邮件列表(mailing-list).
subscribe websites@lists.fedoraproject.org|chinese@lists.fedoraproject.org|linux-kernel@vger.kernel.org
// End of .muttrc
2) 启动mutt
[~]$ mutt
就这么简单! 如果对mutt的各种快捷键不太熟悉的话, 我们可以按下"?"调出帮助.
3.3 procmail
如果你有大量的邮件, 你肯定就会想对收取下来的邮件进行过滤分类, 把一些垃圾文件
扔掉, 把一些重要的文件放到一个专门的邮箱目录... 那么 procmail 就是专门为你设
计的!
1) ~/.procmailrc
[~]$ vi ~/.procmailrc
############################################################
############# Help #############
#
# $ man procmailrc
#
############# Help #############
PATH=/bin:/sbin:/usr/bin:/usr/sbin
SHELL=/bin/bash
MAILDIR=/home/scr/.Mail/inbox/
DEFAULT=$MAILDIR/default/
LOGFILE=$MAILDIR/.procmaillog
#FORMAIL=/usr/bin/formail
#VERBOSE=on # 只在调试时使用
############################################################
############# @126.com #############
:0
* ^(To|Cc):.*lcy3636@126\.com.*
lcy3636_126/default/
:0
* ^(To|Cc):.*tge3636@126\.com.*
tge3636_126/default/
:0
* .*lcy3636@126\.com.*
lcy3636_126/default/
:0
* .*tge3636@126\.com.*
tge3636_126/default/
############################################################
############# @gmail.com #############
:0
* ^(To|Cc):.*(english365)@googlegroups\.com.*
nuoerlz_gmail/list_eng/
:0
* ^(To|Cc):.*shlug@googlegroups\.com.*
nuoerlz_gmail/list_shlug/
:0
* ^From: .*(xxx |support@eoemobile\.net|sap@mailsap\.com|educationfirst@ef\.com).*
/dev/null
:0
* ^(To|Cc): .*(undisclosed-recipients:|undisclosed recipients:|minggong_jjz@hotmail\.com|\
unliste-recipients:).*
/dev/null
:0
* ^Subject:.*(credit|cash|money|debt|sex|sale|loan)
/dev/null
:0
* ^(To|Cc):.*(googlegroups\.com|mutt\.org|kernel\.org).*
nuoerlz_gmail/list_devel/
:0
* .*nuoerlz@gmail\.com.*
nuoerlz_gmail/default/
############################################################
############# default #############
# 最后一条规则: 将到达这的邮件送到默认邮箱
:0
* .*
default/
// End of ~/.procmailrc
linux-dash
A beautiful web dashboard for Linux
项目地址:https://gitcode.com/gh_mirrors/li/linux-dash
对于 procmailrc 文件的语法, 我们可以在网上搜索或"man procmail", 都能找到大量
的文档信息, 这里就不多说了.
2) 对 getmailrc 进行修改
有了 ~/.procmailrc 配置文件, 我们就可以对邮件进行过滤分类了, 但我们还想在收取
邮件的同时就对邮件进行过滤分类, 这我们可以通过对 getmailrc 作一些修改来实现.
修改 [destination] 部分:
[~]$ vi ~/.getmail/getmailrc.nuoerlz.gmail
[retriever] // 设置为gmail的收件服务器
type = SimplePOP3SSLRetriever
server = pop.gmail.com
port = 995
username = nuoerlz@gmail.com // 用户名
password = xxxxxxx // 用户密码
[destination] // 告诉getmail把收取下来的邮件如何储存等
type = MDA_external // 告诉getmail把收取下来的邮件交给外部程序处理
path = /usr/bin/procmail // 由 procmail 来处理
[options] // 一些选项
verbose = 0 // 调试时很有用
delete = false // 在邮箱服务端也保留一份
message_log = ~/.getmail/getmail.gmail.log // ...
// End of getmailrc.nuoerlz.gmail
3) 再收一次
[~]$ /usr/bin/getmail -v -n -r ~/.getmail/getmailrc.nuoerlz.gmail
3.4 msmtp
到目前, 我们已经能收取并过滤分类邮件了, 但发邮件呢?
linux下发邮件的程序有很多, msmtp就很出色, 配置还简单!
1) ~/.msmtprc
[~]$ vi ~/.msmtprc
#msmtp的配置:
defaults
tls on
auth on
tls_certcheck off
logfile ~/.Mail/msmtp.log
# Gmail service
account nuoerlz
host smtp.gmail.com
from nuoerlz@gmail.com
port 587
user nuoerlz@gmail.com
password xxxxxxx
# 126 service
account tge3636
tls off
auth plain
host smtp.126.com
from tge3636@126.com
user tge3636@126.com
password xxxxxxx
# Set a default account
account default : nuoerlz
// End of ~/.msmtprc
2) 简单地使用一下
[~]$ msmtp xxok@163.com
// 随便输入一些内容用ctrl+d结束. 然后到邮箱看看有没有收到.
3) 在mutt中使用msmtp发邮件
记得, 在 ~/.muttrc 中, 我们写有如下的配置:
send-hook . 'set sendmail="/usr/local/msmtp/bin/msmtp"'
如此, 我们在mutt中发邮件时, 就是通过msmtp来发送了.
4. reference
<<使用mutt+msmtp做linux邮件客户端>>
http://storysky.blog.51cto.com/628458/293005
Procmail入门
http://lifegoo.pluskid.org/wiki/Procmail.html#sec6
Timo's procmail tips and recipes
http://lipas.uwasa.fi/~ts/info/proctips.html
http://dreamland.blog.51cto.com/417830/87510
http://home.ustc.edu.cn/~lixuebai/GNU/MuttConfig.html
man /usr/share/doc/mutt-1.5.21/manual.txt
推荐内容
阅读全文
AI总结




A beautiful web dashboard for Linux
最近提交(Master分支:7 个月前 )
186a802e
added ecosystem file for PM2 4 年前
5def40a3
Add host customization support for the NodeJS version 4 年前
更多推荐
相关推荐
查看更多
linux-dash

A beautiful web dashboard for Linux
linux-dash

A beautiful web dashboard for Linux
linux-dash

热门开源项目
活动日历
查看更多
直播时间 2025-03-13 18:32:35

全栈自研企业级AI平台:Java核心技术×私有化部署实战
直播时间 2025-03-11 18:35:18

从0到1:Go IoT 开发平台的架构演进与生态蓝图
直播时间 2025-03-05 14:35:37

国产工作流引擎 终结「996」开发困局!
直播时间 2025-02-25 14:38:13

免费开源宝藏 ShopXO,电商系统搭建秘籍大公开!
直播时间 2025-02-18 14:31:04

从数据孤岛到数据智能 - 企业级数据管理利器深度解析
所有评论(0)