GNU/Linux 下超酷又灵活的 Email 系统
(→fetchmail 取邮件) |
(→sSMTP 发邮件) |
||
(未显示1个用户的17个中间版本) | |||
第11行: | 第11行: | ||
== fetchmail 取邮件 == | == fetchmail 取邮件 == | ||
− | + | fetchmail 的默认配置文件位于当前用户主目录下,即:$HOME/.fetchmailrc,没有可自己建一个 | |
− | < | + | 例如,我的 gmail 账户的 $HOME/.fetchmailrc 例子: |
− | set postmaster " | + | |
+ | <source lang=bash> | ||
+ | set postmaster "comcat" | ||
set bouncemail | set bouncemail | ||
set no spambounce | set no spambounce | ||
第23行: | 第25行: | ||
user "YOUR_GMAIL_USERNAME@gmail.com" there | user "YOUR_GMAIL_USERNAME@gmail.com" there | ||
with password 'YOUR_GMAIL_PASSWD' | with password 'YOUR_GMAIL_PASSWD' | ||
− | is ' | + | is 'comcat' here options no fetchall keep ssl |
mda "/usr/bin/procmail -f %F -d %T" | mda "/usr/bin/procmail -f %F -d %T" | ||
− | </ | + | </source> |
+ | |||
+ | |||
+ | 默认情形下,fetchmail 从服务器取到的邮件后,会检查本地 localhost 的 25 端口,看有没有 SMTP 服务,即其是把取到的邮件 re-route 到本地的 MTA (Mail Transfer Agent),比如 exim4,postfix ... | ||
+ | |||
+ | 如果本地没有安装 MTA,则可在配置文件里指定 MDA (Mail Delivery Agent),上面的配置文件,我们指定 procmail 作为 MDA,fetchmail 取到邮件后,会直接将邮件抛给 procmail 处理。 | ||
<br><br> | <br><br> | ||
== procmail 分捡邮件 == | == procmail 分捡邮件 == | ||
+ | |||
+ | <source lang=bash> | ||
+ | $ sudo apt-get install procmail | ||
+ | </source> | ||
+ | |||
+ | |||
+ | procmail 的配置文件为: $HOME/.procmailrc | ||
+ | |||
+ | 一个 .procmailrc 的简单例子: | ||
+ | |||
+ | <source lang=bash> | ||
+ | MAILDIR=$HOME/mail | ||
+ | DEFAULT=$MAILDIR/inbox/new | ||
+ | |||
+ | # 这个过滤器,把来自 sina.com 和 sohu.com 的邮件全部放入 $MAILDIR/inbox/spam 这个邮箱文件中 | ||
+ | :0: | ||
+ | * ^From: .*@[Ss]ina.com | .*@sohu.com | ||
+ | $MAILDIR/inbox/spam | ||
+ | |||
+ | |||
+ | # 这个过滤器,把标题含有关键字 notice 的邮件全部放入 $MAILDIR/inbox/note 这个邮箱文件中 | ||
+ | :0: | ||
+ | * ^Subject: .*[Nn]otice.* | ||
+ | $MAILDIR/inbox/note | ||
+ | |||
+ | # 其余邮件默认放入 $MAILDIR/inbox/new 这个邮箱文件 | ||
+ | </source> | ||
+ | |||
+ | |||
+ | 邮箱文件都是文本文件 | ||
<br><br> | <br><br> | ||
== Mutt 读邮件 == | == Mutt 读邮件 == | ||
+ | |||
+ | 经过 procmail 处理的邮件,被写入相应的邮箱(文本文件),这个需要写入 Mutt 的配置文件中,告诉 Mutt,去读这个文件 | ||
+ | |||
+ | 以上面的 procmail 配置为例,我们在用户主目录建立如下目录: | ||
+ | |||
+ | <source lang=bash> | ||
+ | $ mkdir -p ~/mail/inbox ~/mail/sent ~/drafts | ||
+ | </source> | ||
+ | |||
+ | |||
+ | 修改 /etc/Muttrc: | ||
+ | |||
+ | <source lang=bash> | ||
+ | # where I keep my mailboxes | ||
+ | set folder="~/mail/" | ||
+ | |||
+ | # new mail box | ||
+ | set spoolfile="~/mail/inbox/new" | ||
+ | |||
+ | # send mail box | ||
+ | set record="~/mail/sent/`date +%Y-%m`" | ||
+ | # save sent messages | ||
+ | set copy=yes | ||
+ | |||
+ | # delay mailbox | ||
+ | set postponed="~/mail/drafts/postponed" | ||
+ | </source> | ||
+ | |||
+ | <br> | ||
+ | |||
+ | <source lang=bash> | ||
+ | alias jeffh Jeffrey C Honig <Jeffrey.Honig@wrs.com> | ||
+ | alias jason "Jason Wessel" <jason.wessel@wrs.com> | ||
+ | ".mutt.alias" 122 行 | ||
+ | </source> | ||
<br><br> | <br><br> | ||
第40行: | 第112行: | ||
== sSMTP 发邮件 == | == sSMTP 发邮件 == | ||
− | < | + | <source lang=bash> |
$ sudo apt-get install ssmtp | $ sudo apt-get install ssmtp | ||
$ vim /etc/ssmtp/ssmtp.conf | $ vim /etc/ssmtp/ssmtp.conf | ||
− | </ | + | </source> |
− | < | + | |
− | + | <source lang=bash> | |
− | + | # The place where the mail goes. The actual machine name is required no | |
− | + | # MX records are consulted. Commonly mailhosts are named mail.domain.com | |
− | + | ||
Root=postmaster # Redirect mail for root@ to postmaster@ | Root=postmaster # Redirect mail for root@ to postmaster@ | ||
− | + | ||
− | AuthPass= | + | Mailhub=smtp.gmail.com:587 # TLS |
+ | |||
+ | AuthUser=YOUR_GMAIL_USERNAME # Your DreamHost mail account | ||
+ | AuthPass=YOUR_GMAIL_PASSWORD # The password for the mail account | ||
UseTLS=YES # Secure connection (SSL/TLS) | UseTLS=YES # Secure connection (SSL/TLS) | ||
UseSTARTTLS=YES | UseSTARTTLS=YES | ||
− | </ | + | |
+ | rewriteDomain=jackslab.org # The host the mail appears to be coming from, seems like gmail can not be rewrited | ||
+ | hostname=jackslab.org # The name of this host | ||
+ | |||
+ | FromLineOverride=YES # Allow the user to specify their own From: address, seems like gmail is not allow | ||
+ | </source> | ||
+ | |||
+ | |||
+ | ;关于发件人: | ||
+ | |||
+ | 发送时,不指定 'From:',则默认的 'From:' 地址就是:你的当前用户名 @ rewriteDomain,ssmtp 会检索 /etc/passwd 获取你的全名,并显示在 'From:' 后 | ||
+ | |||
+ | FromLineOverride=YES 则允许用户用其他地址,覆盖默认的 "当前用户名 @ rewriteDomain" | ||
+ | |||
+ | 最终出现在邮件头的 'From:' 是 log 中 'MAIL FROM:' 后的地址 | ||
+ | |||
+ | |||
+ | ;关于收件人: | ||
+ | |||
+ | ssmtp 命令行后跟的地址,是真正邮送的地址,即显示在 'RCPT TO:' 后的地址 | ||
+ | |||
+ | 默认命令行参数下,ssmtp 不对邮件头中的 'To:', 'Cc:' 作真在的邮送,只是显示在邮件头而已,如果不指定 'To:",则收的邮件,收件人就为空 | ||
+ | |||
+ | |||
+ | 测试发送: | ||
+ | |||
+ | <source lang=bash> | ||
+ | comcat@Pek-tux:/work$ ssmtp -v jack.tan@windriver.com | ||
+ | From: hahaha@gmail.com | ||
+ | To: jack.tan@windriver.com | ||
+ | Cc: help@gmail.com | ||
+ | Subject: hahaha test | ||
+ | |||
+ | test | ||
+ | [<-] 220 mx.google.com ESMTP j6sm28278295qek.8 - gsmtp | ||
+ | [->] EHLO jackslab.org | ||
+ | [<-] 250 ENHANCEDSTATUSCODES | ||
+ | [->] STARTTLS | ||
+ | [<-] 220 2.0.0 Ready to start TLS | ||
+ | [->] EHLO jackslab.org | ||
+ | [<-] 250 ENHANCEDSTATUSCODES | ||
+ | [->] AUTH LOGIN | ||
+ | [<-] 334 VXNlcm5hbWU6 | ||
+ | [->] amlhbmtlbWVuZw== | ||
+ | [<-] 334 UGFzc3dvcmQ6 | ||
+ | [<-] 235 2.7.0 Accepted | ||
+ | [->] MAIL FROM:<hahaha@gmail.com> | ||
+ | [<-] 250 2.1.0 OK j6sm28278295qek.8 - gsmtp | ||
+ | [->] RCPT TO:<jack.tan@windriver.com> | ||
+ | [<-] 250 2.1.5 OK j6sm28278295qek.8 - gsmtp | ||
+ | [->] DATA | ||
+ | [<-] 354 Go ahead j6sm28278295qek.8 - gsmtp | ||
+ | [->] Received: by jackslab.org (sSMTP sendmail emulation); Mon, 18 Mar 2013 11:17:32 +0800 | ||
+ | [->] Date: Mon, 18 Mar 2013 11:17:32 +0800 | ||
+ | [->] From: hahaha@gmail.com | ||
+ | [->] To: jack.tan@windriver.com | ||
+ | [->] Cc: help@gmail.com | ||
+ | [->] Subject: hahaha test | ||
+ | [->] | ||
+ | [->] test | ||
+ | [->] . | ||
+ | [<-] 250 2.0.0 OK 1363576688 j6sm28278295qek.8 - gsmtp | ||
+ | [->] QUIT | ||
+ | [<-] 221 2.0.0 closing connection j6sm28278295qek.8 - gsmtp | ||
+ | </source> | ||
+ | |||
+ | Ctrl-D 退出 | ||
<br><br> | <br><br> | ||
+ | |||
+ | == 资源 == | ||
+ | |||
+ | 一个典型的 .procmailrc 例子: | ||
+ | |||
+ | <source lang=bash> | ||
+ | MAILDIR=$HOME/mail | ||
+ | DEFAULT=$MAILDIR/inbox/new | ||
+ | |||
+ | :0: | ||
+ | * ^Subject:.*Automfg:.* | .*PASSED: rtool CD mfg.* | ||
+ | $MAILDIR/inbox/sjb | ||
+ | |||
+ | :0: | ||
+ | * ^Subject:.*CVS.commit.* | ||
+ | $MAILDIR/inbox/cvs | ||
+ | |||
+ | :0: | ||
+ | * ^To:.*lpd-eng-commits@windriver.com.* | ||
+ | $MAILDIR/inbox/commits | ||
+ | |||
+ | :0: | ||
+ | * ^Subject:.*linux-mod.* | ||
+ | $MAILDIR/inbox/git | ||
+ | |||
+ | :0: | ||
+ | * ^Subject:.*lpg-osc.* | ^CC:.*eng-lpg-osc.* | ||
+ | $MAILDIR/inbox/osc | ||
+ | |||
+ | :0: | ||
+ | * ^Subject:.*[Ss]e[c]?urity.* | ||
+ | $MAILDIR/inbox/sec | ||
+ | |||
+ | :0: | ||
+ | * ^Subject:.*[bB]ug.*[rR]eview.* | ||
+ | $MAILDIR/inbox/bug.rev | ||
+ | |||
+ | :0: | ||
+ | * ^Subject:.*[rtRT]+[Cc]+ore.* | [rR]?eal.*[tT]ime.*[cC]ore.* | ||
+ | $MAILDIR/inbox/rtcore | ||
+ | |||
+ | :0: | ||
+ | * ^CC:.*eng-linuxprod-userspace@windriver.* | ||
+ | $MAILDIR/inbox/userspace | ||
+ | |||
+ | :0: | ||
+ | * ^Subject:.*[eE]scalation.* | .*[Dd]efect.* | ^CC:.*sustain.* | ||
+ | $MAILDIR/inbox/sust | ||
+ | |||
+ | :0: | ||
+ | * ^Subject:.*[Ww][Bb].* | .*[Ww]ork[Bb]ench.* | ||
+ | $MAILDIR/inbox/wb | ||
+ | |||
+ | :0 | ||
+ | * !^Content-Type: message/ | ||
+ | * !^Content-Type: multipart/ | ||
+ | * !^Content-Type: application/pgp | ||
+ | { | ||
+ | :0 fBw | ||
+ | * ^-----BEGIN PGP MESSAGE----- | ||
+ | * ^-----END PGP MESSAGE----- | ||
+ | | formail \ | ||
+ | -i "Content-Type: application/pgp; format=text; x-action=encrypt" | ||
+ | |||
+ | :0 fBw | ||
+ | * ^-----BEGIN PGP SIGNED MESSAGE----- | ||
+ | * ^-----BEGIN PGP SIGNATURE----- | ||
+ | * ^-----END PGP SIGNATURE----- | ||
+ | | formail \ | ||
+ | -i "Content-Type: application/pgp; format=text; x-action=sign" | ||
+ | } | ||
+ | </source> | ||
<br><br><br><br><br><br> | <br><br><br><br><br><br> |
2014年11月11日 (二) 11:20的最后版本
目录 |
[编辑] 1 概述
简单地说就是:fetchmail 从邮件服务器取邮件到本地,经 procmail 过滤分捡后写入相应的 mailbox 文件,邮件客户端 Mutt 读取 mailbox 文件并与用户交互,使用 ssmtp 联系邮件服务器发邮件
fetchmail + procmail + Mutt + Exim4 的方案个人用了 7 年多,效率高,非常适合 Hacker/Geeker
近来发现 sSMTP 更好用,配置简单,风格和 fetchmail 类似,很自然地切到了 sSMTP
[编辑] 2 fetchmail 取邮件
fetchmail 的默认配置文件位于当前用户主目录下,即:$HOME/.fetchmailrc,没有可自己建一个
例如,我的 gmail 账户的 $HOME/.fetchmailrc 例子:
set postmaster "comcat" set bouncemail set no spambounce set properties "" set daemon 60 poll imap.gmail.com protocol IMAP port 993 auth password user "YOUR_GMAIL_USERNAME@gmail.com" there with password 'YOUR_GMAIL_PASSWD' is 'comcat' here options no fetchall keep ssl mda "/usr/bin/procmail -f %F -d %T"
默认情形下,fetchmail 从服务器取到的邮件后,会检查本地 localhost 的 25 端口,看有没有 SMTP 服务,即其是把取到的邮件 re-route 到本地的 MTA (Mail Transfer Agent),比如 exim4,postfix ...
如果本地没有安装 MTA,则可在配置文件里指定 MDA (Mail Delivery Agent),上面的配置文件,我们指定 procmail 作为 MDA,fetchmail 取到邮件后,会直接将邮件抛给 procmail 处理。
[编辑] 3 procmail 分捡邮件
$ sudo apt-get install procmail
procmail 的配置文件为: $HOME/.procmailrc
一个 .procmailrc 的简单例子:
MAILDIR=$HOME/mail DEFAULT=$MAILDIR/inbox/new # 这个过滤器,把来自 sina.com 和 sohu.com 的邮件全部放入 $MAILDIR/inbox/spam 这个邮箱文件中 :0: * ^From: .*@[Ss]ina.com | .*@sohu.com $MAILDIR/inbox/spam # 这个过滤器,把标题含有关键字 notice 的邮件全部放入 $MAILDIR/inbox/note 这个邮箱文件中 :0: * ^Subject: .*[Nn]otice.* $MAILDIR/inbox/note # 其余邮件默认放入 $MAILDIR/inbox/new 这个邮箱文件
邮箱文件都是文本文件
[编辑] 4 Mutt 读邮件
经过 procmail 处理的邮件,被写入相应的邮箱(文本文件),这个需要写入 Mutt 的配置文件中,告诉 Mutt,去读这个文件
以上面的 procmail 配置为例,我们在用户主目录建立如下目录:
$ mkdir -p ~/mail/inbox ~/mail/sent ~/drafts
修改 /etc/Muttrc:
# where I keep my mailboxes set folder="~/mail/" # new mail box set spoolfile="~/mail/inbox/new" # send mail box set record="~/mail/sent/`date +%Y-%m`" # save sent messages set copy=yes # delay mailbox set postponed="~/mail/drafts/postponed"
alias jeffh Jeffrey C Honig <Jeffrey.Honig@wrs.com> alias jason "Jason Wessel" <jason.wessel@wrs.com> ".mutt.alias" 122 行
[编辑] 5 sSMTP 发邮件
$ sudo apt-get install ssmtp $ vim /etc/ssmtp/ssmtp.conf
# The place where the mail goes. The actual machine name is required no # MX records are consulted. Commonly mailhosts are named mail.domain.com Root=postmaster # Redirect mail for root@ to postmaster@ Mailhub=smtp.gmail.com:587 # TLS AuthUser=YOUR_GMAIL_USERNAME # Your DreamHost mail account AuthPass=YOUR_GMAIL_PASSWORD # The password for the mail account UseTLS=YES # Secure connection (SSL/TLS) UseSTARTTLS=YES rewriteDomain=jackslab.org # The host the mail appears to be coming from, seems like gmail can not be rewrited hostname=jackslab.org # The name of this host FromLineOverride=YES # Allow the user to specify their own From: address, seems like gmail is not allow
- 关于发件人:
发送时,不指定 'From:',则默认的 'From:' 地址就是:你的当前用户名 @ rewriteDomain,ssmtp 会检索 /etc/passwd 获取你的全名,并显示在 'From:' 后
FromLineOverride=YES 则允许用户用其他地址,覆盖默认的 "当前用户名 @ rewriteDomain"
最终出现在邮件头的 'From:' 是 log 中 'MAIL FROM:' 后的地址
- 关于收件人:
ssmtp 命令行后跟的地址,是真正邮送的地址,即显示在 'RCPT TO:' 后的地址
默认命令行参数下,ssmtp 不对邮件头中的 'To:', 'Cc:' 作真在的邮送,只是显示在邮件头而已,如果不指定 'To:",则收的邮件,收件人就为空
测试发送:
comcat@Pek-tux:/work$ ssmtp -v jack.tan@windriver.com From: hahaha@gmail.com To: jack.tan@windriver.com Cc: help@gmail.com Subject: hahaha test test [<-] 220 mx.google.com ESMTP j6sm28278295qek.8 - gsmtp [->] EHLO jackslab.org [<-] 250 ENHANCEDSTATUSCODES [->] STARTTLS [<-] 220 2.0.0 Ready to start TLS [->] EHLO jackslab.org [<-] 250 ENHANCEDSTATUSCODES [->] AUTH LOGIN [<-] 334 VXNlcm5hbWU6 [->] amlhbmtlbWVuZw== [<-] 334 UGFzc3dvcmQ6 [<-] 235 2.7.0 Accepted [->] MAIL FROM:<hahaha@gmail.com> [<-] 250 2.1.0 OK j6sm28278295qek.8 - gsmtp [->] RCPT TO:<jack.tan@windriver.com> [<-] 250 2.1.5 OK j6sm28278295qek.8 - gsmtp [->] DATA [<-] 354 Go ahead j6sm28278295qek.8 - gsmtp [->] Received: by jackslab.org (sSMTP sendmail emulation); Mon, 18 Mar 2013 11:17:32 +0800 [->] Date: Mon, 18 Mar 2013 11:17:32 +0800 [->] From: hahaha@gmail.com [->] To: jack.tan@windriver.com [->] Cc: help@gmail.com [->] Subject: hahaha test [->] [->] test [->] . [<-] 250 2.0.0 OK 1363576688 j6sm28278295qek.8 - gsmtp [->] QUIT [<-] 221 2.0.0 closing connection j6sm28278295qek.8 - gsmtp
Ctrl-D 退出
[编辑] 6 资源
一个典型的 .procmailrc 例子:
MAILDIR=$HOME/mail DEFAULT=$MAILDIR/inbox/new :0: * ^Subject:.*Automfg:.* | .*PASSED: rtool CD mfg.* $MAILDIR/inbox/sjb :0: * ^Subject:.*CVS.commit.* $MAILDIR/inbox/cvs :0: * ^To:.*lpd-eng-commits@windriver.com.* $MAILDIR/inbox/commits :0: * ^Subject:.*linux-mod.* $MAILDIR/inbox/git :0: * ^Subject:.*lpg-osc.* | ^CC:.*eng-lpg-osc.* $MAILDIR/inbox/osc :0: * ^Subject:.*[Ss]e[c]?urity.* $MAILDIR/inbox/sec :0: * ^Subject:.*[bB]ug.*[rR]eview.* $MAILDIR/inbox/bug.rev :0: * ^Subject:.*[rtRT]+[Cc]+ore.* | [rR]?eal.*[tT]ime.*[cC]ore.* $MAILDIR/inbox/rtcore :0: * ^CC:.*eng-linuxprod-userspace@windriver.* $MAILDIR/inbox/userspace :0: * ^Subject:.*[eE]scalation.* | .*[Dd]efect.* | ^CC:.*sustain.* $MAILDIR/inbox/sust :0: * ^Subject:.*[Ww][Bb].* | .*[Ww]ork[Bb]ench.* $MAILDIR/inbox/wb :0 * !^Content-Type: message/ * !^Content-Type: multipart/ * !^Content-Type: application/pgp { :0 fBw * ^-----BEGIN PGP MESSAGE----- * ^-----END PGP MESSAGE----- | formail \ -i "Content-Type: application/pgp; format=text; x-action=encrypt" :0 fBw * ^-----BEGIN PGP SIGNED MESSAGE----- * ^-----BEGIN PGP SIGNATURE----- * ^-----END PGP SIGNATURE----- | formail \ -i "Content-Type: application/pgp; format=text; x-action=sign" }