邮件服务器-Qmail
2013-06-13 16:25:27 阿炯

Qmail是一个运行于类Unix操作系统下的邮件传送代理软件,它的作者是丹尼尔·伯恩斯坦(Daniel J. Bernstein),采用C语言开发。


qmail的主要竞争对手是Exim以及Postfix。与它的竞争对手不同的是,Qmail已经许多年没有更新了,用户已经习惯于通过第三方的插件及补丁来使qmail增加新的功能。

它是一个用来代替UNIX下Sendmail软件的邮件传送程序。qmail是面向安全而设计的,作者曾经悬赏500美元来找出qmail的安全漏洞,但是直到2006年,还是没有人能领取这笔奖金。其源代码现已开放为公有领域

qmail is a secure, reliable, efficient, simple message transfer agent. It is designed for typical Internet-connected UNIX hosts. As of October 2001, qmail is the second most common SMTP server on the Internet, and has by far the fastest growth of any SMTP server.

Secure: Security isn't just a goal, but an absolute requirement. Mail delivery is critical for users; it cannot be turned off, so it must be completely secure. (This is why I started writing qmail: I was sick of the security holes in sendmail and other MTAs.)

Reliable: qmail's straight-paper-path philosophy guarantees that a message, once accepted into the system, will never be lost. qmail also optionally supports maildir, a new, super-reliable user mailbox format. Maildirs, unlike mbox files and mh folders, won't be corrupted if the system crashes during delivery. Even better, not only can a user safely read his mail over NFS, but any number of NFS clients can deliver mail to him at the same time.

Efficient: On a Pentium under BSD/OS, qmail can easily sustain 200000 local messages per day---that's separate messages injected and delivered to mailboxes in a real test! Although remote deliveries are inherently limited by the slowness of DNS and SMTP, qmail overlaps 20 simultaneous deliveries by default, so it zooms quickly through mailing lists. (This is why I finished qmail: I had to get a big mailing list set up.)

Simple:
qmail is vastly smaller than any other Internet MTA. Some reasons why:
(1) Other MTAs have separate forwarding, aliasing, and mailing list mechanisms. qmail has one simple forwarding mechanism that lets users handle their own mailing lists.
(2) Other MTAs offer a spectrum of delivery modes, from fast+unsafe to slow+queued. qmail-send is instantly triggered by new items in the queue, so the qmail system has just one delivery mode: fast+queued.
(3) Other MTAs include, in effect, a specialized version of inetd that watches the load average. qmail's design inherently limits the machine load, so qmail-smtpd can safely run from your system's inetd.

Replacement for sendmail:
qmail supports host and user masquerading, full host hiding, virtual domains, null clients, list-owner rewriting, relay control, double-bounce recording, arbitrary RFC 822 address lists, cross-host mailing list loop detection, per-recipient checkpointing, downed host backoffs, independent message retry schedules, etc. qmail also includes a drop-in "sendmail" wrapper so that it will be used transparently by your current UAs.


qmail源代码文件中有几个配置文件可以修改以适合对应的环境:
conf-qmail:此文件包含Qmail的安装目录,默认值是 /var/qmail/
conf-users:此文件包含Qmail需要使用的用户,默认用户是root,alias,(这两个用户在unix下应该已经由系统建立好了,下面的用户应该自己创)qmails,qmaild,qmaill, qmailr,qmailq,qma-ilp。
conf-groups:此文件包含Qmail 需要使用的组,默认的组为qmail(qmails,qmaild,qmaill,qmailr,qmailq,qmailp要属于此组)。
conf-cc:此文件包含Qmail使用的编译器,默认使用cc编译器,如须使用其它C编译器,应该将其替换为此编译器如 gcc。
conf-ld:同conf-cc

在进行安装前系统应该已经安装了make命令。


邮件列表管理是qmail的强项之一。显着特点有:
qmail 允许每个用户处理自己的邮件列表。
qmail 使得设置邮件列表所有者非常容易开展工作。如果用户触摸~user/.qmail-wownever-owner,所有的弹跳都会回到他身上。
qmail 支持 VERP,它允许对任何大小的邮件列表进行完全可靠的自动退信处理。
速度 -- qmail 通过邮件列表爆炸比 sendmail 快两个数量级。例如,qmail 邮件列表中的每条消息仅在76秒内就传递给了全球1000多个主机。
qmail 即使在主机之间也可以自动防止邮件列表循环。
qmail 允许巨大的邮件列表,无随机限制。
qmail 使用相同的简单机制处理别名和转发。例如,Postmaster由~alias/.qmail-postmaster 控制,这意味着跨主机循环检测也适用于别名。
qmail 支持 ezmlm 邮件列表管理器,它可以轻松,自动地处理退信,订阅请求和存档。


qmail是一个模块化设计的邮件系统,每一个子功能都是由一个运行程序来实现的,而每个程序的属性以及运行方式由一个或多个配置文件和环境变量来控制的。在qmail安装成功和启动以后,qmail的相关进程一直在内存中驻留,qmail会不断扫描邮件队列,并且把邮件投递到正确的目的地址。通过ps命令可以查看到qmail的相关进程:
# ps -ax | grep qmail
3282 con- I 0:00.77 qmail-send
3289 con- I 0:00.21 splogger qmail
3290 con- I 0:00.13 qmail-lspawn ./Mialdir/
3291 con- I 0:00.03 qmail-rspawn
3292 con- I 0:00.05 qmail-clean

qmail所有的运行程序都安装在/var/qmail/bin目录下,比较重要的运行程序如下:
1.qmail-smtpd
它的作用是接收远端主机投递的邮件,然后将邮件传递给qmail-queue进行处理。qmail-smtpd是通过SMTP协议和远端主机惊醒通讯的。qmail-smtpd并不是常驻内存的,他需要一个外部程序来激活,本文所做的系统是使用tcpserver来激活的。Tcpserver监视着系统的IP连接请求,如果检测到有SMTP的连接请求,tcpserver就会自动的激活qmail-smtpd,然后将IP连接的控制权交给qmail-smtpd,一旦qmail-smtpd和远端主机建立起SMTP连接后,远端主机就可以将邮件投递到本地的邮件服务器了。

2.qmail-inject
它的作用是接收本地生成并投递的邮件,并把邮件传递给qmail-queue来处理。在邮件传递给qmail-queue之前,qmail-inject先扫面邮件的邮件头,来查看邮件头是否符合RFC822标准,如果不符合它将会自动的更改和修正这个邮件的邮件头。

3.qmail-send
当一个邮件被放入邮件队列之后,qmail-send就开始对该邮件进行处理,它会检查邮件队列中的每一个邮件的状态,对于没有投递过的和投递暂时失败的邮件,对于没有投递过和投递暂时失败的邮件,qmail-send会将目标地址是本地主机的传递给qmail-lspawn,目标地址是远端主机的传递给qmail-rspawn,对于投递永久失败的邮件,qmail-send将会把该邮件传递给qmail-clear,让这个程序永久删除这个邮件。qmail-send是一个常驻内存进程程序,如果qmail-send中止,qmail的其他进程将会自动中止。

4.qmail-clean
它的作用是从邮件队列中删除投递永久失败的邮件。qmail使用多种状态标示来标记邮件,每个邮件在每一次被处理后它的状态表示都会被改变。如果系统当机,系统重新启动以后,qmail-send仍然可以找到邮件队列中上次最后一次成功处理过的邮件的位置,并且从这里重新开始处理邮件队列。如果由于其他原因造成qmail-send不能处理的邮件队列,qmail-send会调用qmail-clean从邮件队列中删除邮件。qmail-clean也是常驻内存的进程。

5.qmail-rspawn
当qmail-send判明邮件目标地址是远端邮件服务器时,qmail-send就会将邮件交给qmail-rspawn,qmail-rspawn的作用是调度邮件的投递时间和顺序,然后激活qmail-remote来进行投递。qmail-rspawn还有一个作用是决定每一个邮件的目标邮件服务器,每次和远端邮件服务器的连接都会调用qmail-remote一次。qmail-rspawn也是常驻内存的进程。

6.qmail-lspawn
功能和qmail-rspawn类似,qmail-lspawn也是被qmail-send调度来投递邮件的,不过qmail-lspawn是负责目标地址是为本地邮件服务器的邮件。

7.qmail-remote
它的作用是通过SMTP协议将邮件投递到远端的用户。邮件是通过qmail-rspawn传递过来的,qmail-remote每次只可以同一个远端主机连接,不过在连接时qmail-remote可以投递这个远端主机上的多个接收者的邮件。投递当中的调度是由qmail-rspamwn来负责的。

8.qmail-local
它的作用是投递本地邮件服务器的邮件,这个程序通常是用来检测因为转发命令使用不当造成的邮件循环故障。

9.qmail-queue
他处理从qmail-inject和qmail-smtpd传递过来的邮件,并把这些邮件传递到邮件队列中,它会扫描每个邮件的发送者和接收者的地址,一般传递给qmail-queue的邮件的标示都是为0,如果为1时,它会认为这个邮件的发送者和接收者的地址要经过特殊格式的处理。



最新版本:1.0


项目主页:http://cr.yp.to/qmail.html