下一步 上一步 目录

4. 我已经全部设置好了,现在怎么办?

现在您已经创建了额外的帐户,您获得了邮件地址 - 和/或 DNS 条目以及转发到您的帐户 ... 并且安装了 Procmail 和 Fetchmail,这样我们就可以开始行动了!:) ... 我们开始吧!

  1. 您需要创建一个 .procmailrc 文件,其中将包含发送给用户的“投递”信息。
  2. 您需要创建一个“nosuchuserfile” - 以便发件人知道他的邮件没有成功投递。
  3. 为了获得最佳效果 :) 您可以使用 crontab 来检查邮件。这是一种在连接到互联网时每 XX 分钟检查邮件的简单方法。

4.1 创建 .fetchmailrc 文件

您将需要创建一个 .fetchmailrc 文件,其中将包含信息(用户名和密码,以及邮件投递代理 (mda) 来处理邮件)。这是一个示例文件 ...

(*** < 文件 > *** 文本 ***) .fetchmailrc

server my.mail.server.com
proto pop3
user myaccountthere
pass deepestsecrets
flush
mda /usr/bin/procmail

此文件将用于获取您的邮件。请使用 fetchmail 程序 "fetchmail -vv" 测试它 - 并查看您的邮件是否被正确传输 ... 会有一些错误 - 因为 procmail 控制文件尚未创建。您可以等待在创建 procmailrc 文件之后再进行测试,但是 - 我要警告您 - 如果有什么错误 :) 它可能是这个文件 :) 它需要由用户帐户本身拥有 - 在我的例子中是 "mailservice",并且需要是“用户可读”的,但不能是“组/世界可读”的 - 因为它包含“主密码” :))。(chmod 600 .fetchmailrc 即可)。

4.2 创建 .procmailrc 文件

此控制文件会将所有邮件转发给其中的用户。如前所述,有两种方法 - “to:”(标头)方式 - 和 “subject”(粗略)方式。该文件将包含要传输到的用户名。所有 “#” 都是注释,并且在不需要时绝对不是必需的 - 这只是为了让您知道我在做什么 ... - 您最好也将其 chmod 为 600 - 这样世界或组中的其他人就不需要这些私有地址了,对吧 :) ... 它也需要由用户拥有(例如 “mailservice”):)。“nosuchuserfile” 是对发件人的“退回” - 如果在 procmailrc 文件中找不到用户(因此邮件未投递)... - 这样发件人就知道邮件没有成功投递。

对于 “header (to:)” 传输

(*** < 文件 > *** 文本 ***) .procmailrc

# this line is for debugging purposes only ! it should be removed for
# ethical purposes - since you can read all mail passed trough your mail-
# server ... - all mail will be copied to the file "passtrough" before
# going to the users ... herein you can look what went wrong ...
:0 c
        passtrough

# the mail with header "to: freaker@mydom.com" will be forwarded directly
# to me, the other mail will pass this option ... 
:0 
* ^To:.*freaker@mydom.com
! freaker

# the mail to root@mydom.com will be forwarded to root ... as well postmaster!
:0 
* ^To:.*root@mydom.com
! root

:0 
* ^To:.*postmaster@mydom.com
! postmaster


# the mail to barbara@mydom.com will be forwarded to barbara AND will be
# forwarded to her private email address !

:0 c
* ^To:.*barbara@mydom.com
! barbara@her.private.one

:0 
* ^To:.*barbara@mydom.com
! barbara

# the mail to johnny@mydom.com and johnny@hisdom.com will be forwarded to johnny

:0
* (^To:.*johnny@mydom.com)|(^To:.*johnny@hisdom.com)
! freaker

# the mail to hans@mydom.com and all carbon copys will be forwarded to hans

:0
* (^To:.*hans@mydom.com)|(^CC:.*hans@mydom.com)
! hans

# this lines will BOUNCE the mail to the sender - when it is not delivered to
# one of above users ... it will send the file "nosuchuser" into the mail
# body as reply ... be aware ! you need to make such file ! - mine contains
# "well, the user you wanted to reach does not exist on this server, please
# try again, it could be the user is not present anymore".
#
:0
  |(/usr/bin/formail -r -k \
     -A"X-loop: mailservice@mydomain.dom "| \
       /usr/bin/gawk '{print }\
       /^/ && !HEADER \
         { system("/bin/cat nosuchuser"); \
         print"--" ;\
         HEADER=1 }' ) |\
         /usr/bin/sendmail -t


exit

对于 “subject: touser” 传输

(*** < 文件 > *** 文本 ***) .procmailrc

# this line is for debugging purposes only ! it should be removed for
# ethical purposes - since you can read all mail passed trough your mail-
# server ... - all mail will be copied to the file "passtrough" before
# going to the users ... herein you can look what went wrong ...
:0 c
        passtrough

# the mail with header "to: freaker@ibm.net" will be forwarded directly
# to me, the other mail will pass this option ... When you got a "dedicated"
# email address to receive your "mailservice thingy's" on - you don't need
# to use this line :) 
:0 
* ^To:.*freaker@ibm.net
! freaker

# all mail with as subject "root" will be forwarded to root !
:0
* ^Subject:.root
! root

# all mail to "subject: barbara" will be forwarded to barbara ...
:0
* ^Subject:.barbara
! barbara

# all mail to "subject: paul" will be forwarded to his external email addr.
:0
* ^Subject:.paul
! paul@his.personal.emailaddress

# all mail to "subject: john" will be forwarded to his account at your server
# and a copy will go to his private email address ... 
:0 c
* ^Subject:.john
! john@his.personal.emailaddress

:0 
* ^Subject:.john
! john

# All the mail from ibm, with their updates and information, will go to                                
# freaker, as he is the one who will administrate the mailservice, and
# as ibm doesn't want to get the bounce putten below !! ... this is
# neccesary if your mail provider sends "newsletters" etc...
:0
* ^From:.*newsletter@ibm.net
! freaker

# All messages from the daemon should been thrown away, or in my case, will
# be saved to a file ... (use /dev/null to throw to endless pits of The Abyss)
:0
* ^FROM_DAEMON
throwaway

# this lines will BOUNCE the mail to the sender - when it is not delivered to
# one of above users ... it will send the file "nosuchuser" into the mail
# body as reply ... be aware ! you need to make such file ! - mine contains
# some text like "user not found in subject line, please use "Subject: user"
# to write a mail to the user, like example "subject: freaker" would send a
# mail to freaker." The file can be long, but also small :) ... the
# "mailservice@mydomain.dom" will prevent to loop between your server and
# the other server - it needs to have the EXACT email address used !.
# Else you could create an endless loop with a server what sends mail
# to "your email address" with as subject something like "don't spend 500$
# at your ..." etc...
:0
  |(/usr/bin/formail -r -k \
     -A"X-loop: mailservice@mydomain.dom "| \
       /usr/bin/gawk '{print }\
       /^/ && !HEADER \
         { system("/bin/cat nosuchuser"); \
         print"--" ;\
         HEADER=1 }' ) |\
         /usr/bin/sendmail -t

exit

4.3 “nosuchuserfile”

(*** < 文件 > *** 文本 ***) nosuchuser

The user you wanted to contact is not present at this system.

Please use the subject line as recipient - example "subject: freaker" would
send mail to freaker on this system.

4.4 “crontab 文件”。

如果您不知道 crontab 如何工作 :) 最好阅读手册 :) ... 您需要创建一个 “checkmail” 文件 - 它将检查链接是否已连接,以及 cronfile 本身 ... - 我正在使用 ppp 链接 :) 所以 - 这是一个示例,说明如何在 ppp 链接连接时查看 - 以及使用 cron 每 10 分钟轮询一次。看起来很粗略 - 但并非如此!

checkformail

.checkformail 文件将被调用(也需要是可执行的)- 并检查 ppp 链接是否已连接。如果已连接 - 则它将获取邮件。当您使用下面的 cronentry 时,Crontab 将使用此文件 ...

(*** < 文件 > *** 代码 ***) .checkformail

#!/bin/sh
#

        cd /home/mailservice

        if [ -f /var/run/ppp0.pid ]; then
        /usr/local/bin/fetchmail -s > /dev/null 2>&1
fi

crontab

此 cronentry 文件需要加载到 crontab 中,并将每 10 分钟调用 .checkformail。它不会写入任何邮件或向控制台提供任何信息 - 因为我将所有内容都重定向到 null。

(*** < 文件 > *** 文本 ***) cronentry

0,10,20,30,40,50 * * * *  /home/mailservice/.checkformail 1> /dev/null 2> /dev/null

4.5 “在管理员站点”。

嗯,这应该在使用 “A 方法” 时完成 ... 在管理员站点,以便电子邮件从完整的域发送到一个用户名。这非常简单,一旦您完成它 - 它就像地狱一样工作。如果您的系统管理员(上行链路)有另一种方法,则这不是必要的,并且在您这边也不是必要的!!!!

当使用较新版本的 sendmail 时,“旧的 sendmail”技巧可能不起作用,因此请参阅 “新的 sendmail” 主题,以使您的邮件路由工作。

(旧 sendmail)向 sendmail.cf 添加一些行

将以下行添加到您的 /etc/sendmail.cf 文件中,以便读取 domains 文件。请注意,“ruleset 98” 是如下添加的,因为 - 一旦您遇到错误 :) 找到它们就像地狱一样!(我可以知道这一点 :) Duh)。

(*** < 文件 > *** 添加 ***) /etc/sendmail.cf

# Database of handled domains

Kmaildomains btree /etc/maildomains.db

# Add these lines *IN* Ruleset 98 ! (under Ruleset 98).

R$+ < @ $+  . >              $: $1 < @ $2 > .
R$+ < @ $+ > $*              $: $(maildomains $1@$2 $: $1 < @ $2 > $3 $)
R$+ < @ $+ > $*              $: $(maildomains $2 $: $1 < # $2 > $3 $)
R$+ < @ $* > .               $: $1 < @ $2 . >

(新 sendmail)向 sendmail.cf 添加一些行

对于较新的 sendmail 版本(已使用 sendmail v8.8.7、8.8.8 测试)。忽略方法 A,并添加以下行 ...

(*** < 文件 > *** 添加 ***) /etc/sendmail.cf

# Database of handled domains

Fw/etc/sendmail.cw
Kvirtuser btree /etc/maildomains.db

*OR*

Fw/yourhomedir/sendmail.cw
Kvirtuser btree /yourhomedir/maildomains.db

(新 sendmail)编辑 /etc/sendmail.cw(或 /yourdir/sendmail.cw)文件

如果您正在为 sendmail.cw 文件使用另一个 “位置”,那么请将 “/etc/sendmail.cw” 替换为 “/yourhomedirectory/sendmail.cw”。将此 sendmail.cw 文件放入您的主目录的优点是,您不需要 root 权限即可更改要接收的域。但是 - 如果使用不当,这可能会带来安全风险!

此文件可能已经存在,或者需要创建,如果它已经存在,请确保您没有覆盖旧数据 - 否则我需要将您转到我的精细免责声明 :)

首先创建一个 /etc/sendmail.cw 文件,它将用于将域 “发送” 到特定用户 ... 这是一个示例 ...(正如您已经知道的,名称 “mailservice” 可以是您想要的任何名称 - 它甚至可以是您的登录名(就像我的 freaker 一样)。

(*** < 文件 > *** 文本 ***) /etc/sendmail.cw

mydomain.dom            mailservice

创建 /etc/maildomains 文件

首先创建一个 /etc/maildomains 文件,它将用于将域 “发送” 到特定用户 ... 这是一个示例 ...(正如您已经知道的,名称 “mailservice” 可以是您想要的任何名称 - 它甚至可以是您的登录名(就像我的 freaker 一样)。(您可以将此 /etc/maildomains 放在 /yourhomedir/maildomains 中,如前所述,只需更改路径 :)

对于旧版本的 sendmail

(*** < 文件 > *** 文本 ***) /etc/maildomains

mydomain.dom            mailservice

对于较新版本的 sendmail

(*** < 文件 > *** 文本 ***) /etc/maildomains

@mydomain.dom           mailservice

让它工作吧!

对于新旧 sendmail 版本,您都需要生成 btree(数据库)文件,您需要执行以下操作

cd /etc    (or /yourhomedir)
makemap btree maildomains < maildomains

之后,杀死 sendmail 守护进程,然后重新启动它。它现在应该可以工作了!祝你好运 :)


下一步 上一步 目录