作者:王兴宇 <wxy@cngnu.org>
版本:0.20
版权:gpl
发布日期:2004-01-29
目录
1. 概述
1.1. 目的
本文试图介绍如何在一个linux平台上安装一套功能完整的邮件系统。这里我们以postfix做smtp服务器、courier-imap做pop3/imap4服务器、通过cyrus-sasl对存储在mysql数据库中的用户进行验证和授权,并且使用imp来提供一个完善的webmail界面。
这个邮件系统的设计目标是提供一个可扩充的、具备大多数功能的邮件系统。
如果希望使用cyrus-imap做为pop3/imap4服务器,可以参阅本文的姊妹篇:http://www.cngnu.org/technology/postfix_i.html。
本文的最新版本可以在这里找到:http://www.cngnu.org/technology/postfix_ii.html
有关本文所涉及的技术问题,请到http://www.anti-spam.org.cn/forums/的mail版讨论,我会尽快回复的,请勿就技术问题给我发邮件。
本文的版权遵循gpl,可以在不删除版权信息和注明修改的情况下任意传播。
1.2. 更新历史
- 2004-01-29 第一次发布,版本0.20。
1.3. todo
- 增加邮件列表功能
- 增加ssl部分的内容
- 翻译:希望有能力的朋友可以翻译这篇文章为英文,这样国外的朋友也可以看到
1.4. 鸣谢
2. 系统功能
系统逻辑结构:
+--------------------------------------------------------------+ | | | 25/25 25/25 110/993 143/995 80/443 | | incoming outgoing pop3 imap web-mail | | /\ /\ /\ /\ /\ | | || || || || || | | \/ \/ \/ \/ \/ | +---------------------------------+----------------+-----------+ | postfix | | imp | | +------------------+ +-----------+ | | cyrus-sasl | courier-imap | +----------+ +------------------+--------------+ | | maildrop | |authdaemond.mysql |(authmysqlrc) | | +----------+---+------------------+--------------+-------------+ | maildir/ | mysql | maildir/ | +----------+-------------------------------------+-------------+
整个系统对外的界面包括几个部分,用来发信的smtp、用来收信的pop3和imap、以及一个web界面的邮件使用系统。这里没有提供web界面的管理工具,需要大家自行依据实际需要开发。如果需要商业应用,可以购买cem产品(http://cngnu.net/products/cem/),其中包括了完善的管理界面和优化的邮件服务器环境。
mysql作为系统中存储数据的核心,它存储了用户的信息。这个信息不但用于pop3/imap和smtp auth的认证需要,而且也为postfix提供了本地接收者列表、邮件转发功能和过滤功能开关。
认证分为两种类型,postfix中的发信认证是通过sasl对mysql进行查询进行的;courier-imap的收信认证是通过courier-imap的mysql支持进行的。
用户的信件是存储在标准的(qmail格式)maildir/中的。postfix接收到信件后通过maildrop投递到用户的maildir/中。courier-imap通过认证后访问maildir/来读取信件。
3. 系统基本前提
本文以linux系统为目标平台,支持多数的linux平台如redhat 7.x/8.x/9.x/as2.1/as3、mandrake 8.x/9.x等,理论上也会支持其他的linux发行版,甚至其他的unix系统。
这里以redhat linux advance server enterprise v 3.0 (以下简称as3)为说明平台。我采用了最基本的as3安装,只选择了“web server”、“dns name server”、“mysql database server”、“development tools”和“kernel development”等软件包组(“core”和“base”组是默认必选的软件包)。
除此外,还需要额外安装以下rpm:
1、php-mysql-4.3.2-8.ent.i386.rpm(在cd3)
4. 安装mysql
4.1. 下载
as3默认是只包含mysql除了服务器程序外的部分的,所以需要从rpmfind下载mysql的源rpm重建(最好使用源码包,采用mysql.com提供的rpm和bin包都可能在其它使用mysql的部分编译时候出现错误)。
|
[root@mail root]# cd /usr/src [root@mail src]# wget ftp://rpmfind.net/linux/redhat/enterprise/3/en/os/i386/srpms/mysql-3.23.58-1.src.rpm |
4.2. 编译与安装
|
[root@mail src]# rpmbuild -bb mysql-3.23.58-1.src.rpm [root@mail src]# cd redhat/rpms/i386 [root@mail i386]# rpm -ivh mysql-server-3.23.58-1.i386.rpm |
为提高mysql的安全性,使之只监听在本地打环端口,修改/etc/my.cnf:
|
[root@mail i386]# cd [root@mail root]# vi /etc/my.cnf |
在[mysqld]小节里面添加:
| bind-address=127.0.0.1 |
并设置其开机时候自动运行:
|
[root@mail root]# chkconfig --level 0123456 mysqld on |
4.3. 运行
启动命令如下:
|
[root@mail i386]# /etc/init.d/mysqld start |
4.4. 测试
启动mysql后,首先检查日志/var/log/messages有无错误信息,然后检查进程,应该有如下进程存在:
|
[root@mail root]# pstree | grep mysqld
|-safe_mysqld---mysqld
|
接着检查端口,应该有如下端口打开:
|
[root@mail root]# netstat -an | grep listen
tcp00 127.0.0.1:33060.0.0.0:*listen |
4.5. 建立数据库
mysql安装配置好以后,创建如下sql脚本mail.sql:
|
create database mail; grant all on mail.* to mail@localhost identified by "secret"; flush privileges;
use mail; create table user (
insert into user (username,password,clear_password, values (trueuser,$1$pi.wvgbx$a3duczbnby76jnzlqwqcq/,testpw, trueuser,cngnu.org,/data/mail/trueuser,/data/mail/trueuser/maildir, trueuser@cngnu.org), virtualuser@cngnu.org,cngnu.org,/data/mail/cngnu.org/virtualuser, |
|
[root@mail root]# mysql < mail.sql |
在mysql中创建邮件用户数据库,并添加两个测试邮箱:
- 非虚拟域邮箱“trueuser”,密码是“testpw”
- 虚拟域邮箱“virtualuser@cngnu.org”,密码是“testpw”
上面的mail数据库的user表用来保存用户信息:
- username是用户名。username不但作为认证的字段,而且是本地邮箱查找条件(见下面的postfix的virtual.mysql)。这里采用了加密密码是为了更好的安全性。对于
- 非虚拟域邮箱:username字段是邮件的本地部分(“@”前面的部分)
- 虚拟域邮箱:username字段是邮件地址全称
- password字段是邮箱的md5-crypt密码,clear_password是明文密码。邮箱的密码是“testpw”,加密后的(md5-crypt)密文是“$1$pi.wvgbx$a3duczbnby76jnzlqwqcq/”(可以通过系统的passwd命令来添加一个用户,生成密码,然后从/etc/shadow中复制。)。保存两个密码是由于cyrus-sasl的mysql认证方式不支持加密的密码,而courier-imap的mysql认证却使用加密的密码。
- forward字段默认情况下与username一样,在此情况下,邮件递交到本地邮箱(由于postfix区分邮箱的大小写,所以通过这样的一个转发,正好可以消除大小写的区别);如果forward字段是另外一个用户名或者邮件地址,则该邮件被转发到别的用户或其它邮件地址。
- domain字段用来快速找出某个域下存在的邮箱,仅为管理方便使用。
- maildir字段用来给maildrop指出邮件投递那里,homedir字段是邮件用户的主目录,通常指向一个任意存在的公共位置,不过可以使每个用户都拥有自己的主目录,在其中可以放入maildrop的过滤规则来实现用户级别的过滤。
- mail字段是邮件地址全称。对于非虚拟域邮箱,它包含了本地部分外的域部分;对于虚拟域邮箱,它和username字段一样。一方面是为了管理方便使用,同时该字段还用来做maildrop递交和全局过滤控制filter的查找条件(见filter字段及下面postfix的filter.mysql)。
- gid字段和uid字段是系统使用的投递用户id,即maildrop的运行身份(在postfix的master.cf指定)。
- filter字段用于控制该邮箱是否接受服务器的全局邮件过滤。该值设置为“ok”或为空表示对该邮箱不进行过滤;设置为“dunno”表示对该邮箱进行postfix中定于的全局过滤。该值可以是任何合法的postfix的access过滤规则。
- partition字段用于指明邮箱存储的cyrus-imap邮件分区。可以建立多个不同的邮件分区。仅为了管理方便使用。
- quota字段指定邮箱的磁盘限额。仅为了管理方便使用。
- status字段用来指示该用户是否有效,可以通过修改该值为0来临时禁止某个用户。
5. 安装cyrus-sasl
5.1. 下载
目前多数版本的linux中都已经内置了cyrus-sasl,但是并不符合我们的需要,所以我们需要从rpmfind.net下载cyrus-sasl的源rpm修改后重建并更新系统的cyrus-sasl:
ftp://rpmfind.net/linux/redhat/enterprise/3/en/os/i386/srpms/cyrus-sasl-2.1.15-3.src.rpm
|
[root@mail root]# cd /usr/src [root@mail src]# wget ftp://rpmfind.net/linux/redhat/enterprise/3/en/os/i386/srpms/cyrus-sasl-2.1.15-3.src.rpm |
5.2. 编译与安装
安装cyrus-sasl源rpm:
|
[root@mail src]# rpm -ivh cyrus-sasl-2.1.15-3.src.rpm |
应用以下补丁文件cyrus-sasl.spec.patch:
| *** cyrus-sasl.spec 2003-08-22 03:22:37.000000000 +0800 --- /root/cyrus-sasl.spec 2004-01-16 12:56:30.000000000 +0800 *************** *** 5,11 **** summary: the cyrus sasl library. name: cyrus-sasl version: 2.1.15 ! release: 3 license: freely distributable group: system environment/libraries source0: ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/cyrus-sasl-%{version}.tar.gz --- 5,11 ---- summary: the cyrus sasl library. name: cyrus-sasl version: 2.1.15 ! release: 3m license: freely distributable group: system environment/libraries source0: ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/cyrus-sasl-%{version}.tar.gz *************** *** 73,78 **** --- 73,87 ---- the %{name}-md5 package contains the cyrus sasl plugins which support cram-md5 and digest-md5 authentication schemes. + %package mysql + requires: %{name} = %{version}-%{release} + group: system environment/libraries + summary: mysql support for cyrus sasl. + + %description mysql + the %{name}-mysql package contains the cyrus sasl plugins which support + mysql auxprop authentication schemes. + %prep %setup -q -c -a 2 pushd cyrus-sasl-%{cs1_version} *************** *** 167,173 **** --enable-cram \ --enable-digest \ --enable-plain \ ! --enable-login # --enable-auth-sasldb -- experimental make sasldir=%{_plugindir2} popd --- 176,183 ---- --enable-cram \ --enable-digest \ --enable-plain \ ! --enable-login \ ! --with-mysql # --enable-auth-sasldb -- experimental make sasldir=%{_plugindir2} popd *************** *** 273,278 **** --- 283,293 ---- %{_plugindir2}/*digestmd5*.so* %{_plugindir2}/*digestmd5*.la + %files mysql + %defattr(-,root,root) + %{_plugindir2}/*mysql*.so* + %{_plugindir2}/*mysql*.la + %files gssapi %defattr(-,root,root) %{_plugindir}/*gssapi*.so* *************** *** 300,305 **** --- 315,321 ---- %{_plugindir2}/*anonymous*.a %{_plugindir2}/*crammd5*.a %{_plugindir2}/*digestmd5*.a + %{_plugindir2}/*mysql*.a %{_plugindir2}/*gssapi*.a %{_plugindir2}/*login*.a %{_plugindir2}/*plain*.a |
这个补丁主要对原有的cyrus-sasl库添加了对mysql认识的支持。
|
[root@mail src]# cd redhat/specs [root@mail specs]# patch -p0 < ../../cyrus-sasl.spec.patch |
如果没有出现错误,然后重建rpm:
|
[root@mail specs]# rpmbuild -bb cyrus-sasl.spec |
重建完成后更新系统的cyrus-sasl:
|
[root@mail specs]# cd ../rpms/i386 [root@mail i386]# rm -rf cyrus-sasl-debuginfo*.rpm [root@mail i386]# rpm -uvh cyrus-sasl*.rpm |
5.3. 配置
设置postfix使用sasl的mysql扩展认证来支持smtp auth认证:
|
[root@mail i386]# vi /usr/lib/sasl2/smtpd.conf |
内容如下:
| pwcheck_method: auxprop mech_list: plain login mysql_user: mail mysql_passwd: secret mysql_hostname: localhost mysql_database: mail mysql_statement: select clear_password from user where (username = %u or mail = %u@%r) limit 1 |
对于cyrus-sasl-2.1.17版本的sasl,其对mysql、postgresql等数据库的支持已经合并为一个sql扩展,具体的配置语句略有不同。
整个系统只有postfix的smtp auth使用了sasl认证。courier-imap的认证使用了它自己的mysql扩展。
6. 安装maildrop
6.1. 下载
http://sourceforge.net/projects/courier/
|
[root@mail i386]# cd /usr/src [root@mail src]# wget http://heanet.dl.sourceforge.net/sourceforge/courier/maildrop-1.6.3.tar.bz2 |
6.2. 编译与安装
先添加用户maildrop,其uid和gid是mysql数据库字段uid和gid的值:
|
[root@mail src]# groupadd -g 450 maildrop [root@mail src]# useradd -g 450 -u 450 -c maildrop -m -d/data/mail -s/no/shell maildrop |
编译maildrop,并增加mysql支持和限额支持:
|
[root@mail src]# tar -xvjf maildrop-1.6.3.tar.bz2 [root@mail src]# cd maildrop-1.6.3
[root@mail maildrop-1.6.3]# ./configure \ > --without-db --enable-sendmail=/usr/sbin/sendmail \ > --enable-trusted-users=root maildrop \ > --enable-maildropmysql --with-mysqlconfig=/etc/maildrop.mysql \ > --enable-maildirquota --with-trashquota --with-dirsync [root@mail maildrop-1.6.3]# make [root@mail maildrop-1.6.3]# make install-strip [root@mail maildrop-1.6.3]# make install-man [root@mail maildrop-1.6.3]# cp maildropmysql.config /etc/maildrop.mysql |
6.3. 配置
然后编辑配置文件/etc/maildrop.mysql:
|
[root@mail maildrop-1.6.3]# vi /etc/maildrop.mysql |
内容如下
|
hostname localhost |
7. 安装postfix
7.1. 下载
http://www.postfix.org/ftp-sites.html
|
[root@mail maildrop-1.6.3]# cd /usr/src [root@mail src]# wget http://postfix.energybeam.com/source/official/postfix-2.0.16.tar.gz |
7.2. 编译与安装
如果你的系统上原来有sendmail,先将其停止并将其文件改名:
|
[root@mail src]# /etc/init.d/sendmail stop [root@mail src]# chkconfig --level 0123456 sendmail off [root@mail src]# mv /usr/bin/mailq /usr/bin/mailq.orig [root@mail src]# mv /usr/sbin/sendmail /usr/sbin/sendmail.orig |
然后添加两个组:postfix和maildrop和一个用户:postfix
|
[root@mail src]# groupadd -g 400 postfix [root@mail src]# groupadd -g 401 postdrop [root@mail src]# useradd -u 400 -g 400 -c postfix -m -d/no/where -s/no/shell postfix |
这里的组和用户的id是系统中未使用的id。
编译postfix,并支持mysql和sasl:
|
[root@mail src]# tar -xvzf postfix-2.0.16.tar.gz [root@mail src]# cd postfix-2.0.16
[root@mail postfix-2.0.16]# make -f makefile.init makefiles \ > ccargs=-duse_sasl_auth -dhas_mysql -i/usr/include/mysql -i/usr/include/sasl \ > auxlibs=-l/usr/lib/mysql -l/usr/lib/sasl2 -lmysqlclient -lsasl2 -lz -lm [root@mail postfix-2.0.16]# make install |
安装时,安装程序会提问一些问题,可以直接按回车采用默认值。
这里切记要指定正确的sasl2的include和lib位置。由于现在很多linux发行版上都已经带有了sasl,如果不指定的话,很可能会使用了不同版本的头文件和库,在这种情况下,每次连接smtp时,smtpd就会发生致命错误“fatal: sasl per-connection server init...”而崩溃。
给postfix用户做一个系统别名,并将超级用户的邮箱转发到一个普通用户如tester。使用/etc/postfix/aliases别名数据库:
|
[root@mail postfix-2.0.16]# cd postfix [root@mail postfix]# echo root: virtualuser@cngnu.org >> /etc/postfix/aliases |
生成/etc/postfix/aliases别名数据库:
| [root@mail postfix]# postalias /etc/postfix/aliases |
生成/etc/postfix/virtual的db库:
|
[root@mail postfix]# postmap virtual |
保留db格式的virtual库是为了系统临时增加转发方便起见。
7.3. 配置
修改/etc/postfix/master.cf中的关于maildrop的配置:
|
[root@mail postfix]# vi master.cf |
将如下两行:
| maildrop unix - n n - - pipe flags=drhu user=vmail argv=/usr/local/bin/maildrop -d ${recipient} |
修改为:
| maildrop unix - n n - - pipe flags=drhu user=maildrop argv=/usr/local/bin/maildrop -d ${recipient} |
这里要把maildrop的路径修改为上面安装的maildrop实际安装路径,用户maildrop是我们上面添加过的。 记着flags=...这行前面是以空格缩进的。
|
[root@mail postfix]# vi main.cf |
修改/etc/postfix/main.cf的配置:
|
myhostname = mail.cngnu.org mydomain = cngnu.org myorigin = $mydomain mydestination = $mydomain,$myhostname mynetworks_style = host
alias_maps = hash:/etc/postfix/aliases alias_database = hash:/etc/postfix/aliases
home_mailbox = maildir/
mailbox_transport = maildrop fallback_transport = maildrop
virtual_maps = hash:/etc/postfix/virtual,mysql:/etc/postfix/virtual.mysql
smtpd_sasl_auth_enable = yes broken_sasl_auth_clients = yes smtpd_sasl_security_options = noanonymous
smtpd_recipient_restrictions = |
如果希望支持更多的虚拟域,可以在mydestination参数后面加上你所要支持的域即可。
通过virtual和virtual.mysql为系统提供了邮箱本地查询表。
在上面的配置文件里面使用了sasl来进行smtp发信认证。
通过smtpd_recipient_restrictions提供了基本的反垃圾邮件功能。首先允许本地网络(这里是本机)和通过sasl认证的用户可以使用本服务器发信;然后检查每个用户的全局邮件过滤功能是否打开,如果关闭则不进行后面的反垃圾邮件检查;其后是一些postfix支持的基本反垃圾邮件功能。
创建/etc/postfix/virtual.mysql,它提供了本地用户和邮件转发功能。forward字段默认是指向用户的存储邮箱名的(courier-imap所管理的邮箱名称),即进行本地投递;如果forward字段是另外一个用户名或者邮件地址,则该邮件被转发到别的用户或其它邮件地址。
|
[root@mail postfix]# vi virtual.mysql |
|
# # mysql config file for alias lookups on postfix #
# the user name and password to log into the mysql server hosts = localhost user = mail password = secret
# the database name on the servers dbname = mail
# the table name table = user
select_field = forward where_field = username additional_conditions = and status = 1 limit 1 |
|
[root@mail postfix]# vi filter.virtual |
|
# # mysql config file for filter flag on postfix #
# the user name and password to log into the mysql server hosts = localhost user = mail password = secret
# the database name on the servers dbname = mail
# the table name table = user
select_field = filter # ok : ignore filter # dunno : filter where_field = mail additional_conditions = and status = 1 limit 1 |
7.4. 运行
启动命令如下:
|
[root@mail postfix]# /usr/sbin/postfix start |
可以使用文末所附脚本设置postfix在系统启动时候自动运行。
7.5. 测试postfix
启动postfix后,首先检查日志/var/log/messages有无错误信息,然后检查进程,应该有如下进程存在:检查端口及进程:
|
[root@mail postfix]# pstree |grep master
|-master-+-pickup
|
接着检查端口,应该有如下端口打开:
|
[root@mail postfix]# netstat -an |grep listen
tcp00 0.0.0.0:250.0.0.0:*listen
|
再检测smtp服务是否正常:
|
[root@mail postfix]# telnet localhost 25 trying 127.0.0.1... |
使用如下命令测试postfix的smtp的认证(这里仅测试了“virtualuser@cngnu.org”,“trueuser”请自行测试):
plain认证方式:
|
[root@mail postfix]# perl -mmime::base64 -e \ > print encode_base64("virtualuser\@cngnu.org\000virtualuser\@cngnu.org\000testpw");
[root@mail postfix]# telnet localhost 25 trying 127.0.0.1... ehlo cngnu 250-mail.cngnu.org 250-pipelining 250-size 10240000 250-vrfy 250-etrn 250-auth login plain 250-auth=login plain 250-xverp 250 8bitmime auth plain dmlydhvhbhvzzxjay25nbnuub3jnahzpcnr1ywx1c2vyqgnuz251lm9yzwb0zxn0chc== 235 authentication successful quit 221 bye connection closed by foreign host.
[root@mail postfix]# perl -mmime::base64 -e \ > print encode_base64("trueuser\000trueuser\000testpw");
|
login认证方式:
|
[root@mail postfix]# perl -mmime::base64 -e \ > print encode_base64("virtualuser\@cngnu.org"); dmlydhvhbhvzzxjay25nbnuub3jn [root@mail postfix]# perl -mmime::base64 -e \ > print encode_base64("testpw"); dgvzdhb3
[root@mail postfix]# telnet localhost 25 trying 127.0.0.1... ehlo cngnu 250-mail.cngnu.org 250-pipelining 250-size 10240000 250-vrfy 250-etrn 250-auth login plain 250-auth=login plain 250-xverp 250 8bitmime auth login 334 vxnlcm5hbwu6 dmlydhvhbhvzzxjay25nbnuub3jn 334 ugfzc3dvcmq6 dgvzdhb3 235 authentication successful quit 221 bye connection closed by foreign host.
[root@mail postfix]# perl -mmime::base64 -e \ > print encode_base64("trueuser"); dhj1zxvzzxi= [root@mail postfix]# perl -mmime::base64 -e \ > print encode_base64("testpw"); dgvzdhb3
|
此时,由于还没有安装courier-imap以及创建邮箱,所以还不能提交邮件,请继续下一步。
这里使用perl里面的mime::base64模块(如果需要安装:perl -mcpan -e install mime::base64;)来取得这个验证串:perl -mmime::base64 -e print base64_encode("用户名\000用户名\000密码");来得到mime-base64编码的验证串(“\000”是八进制的ascii(0)字符)。此外,你也可以使用mmencode来生成,mmencode可以在metamail这个包里面找到。
8. 安装courier-imap
8.1. 下载
http://sourceforge.net/projects/courier/
|
[root@mail postfix]# cd /usr/src [root@mail src]# wget http://umn.dl.sourceforge.net/sourceforge/courier/courier-imap-2.2.1.tar.bz2 |
8.2. 编译与安装
编译cyrus-imap,并取消kerberos支持(在redhat中,kerberos库有问题,很难编译通过,mandrake则可以通过;此外,我们也不需要kerberos的支持)和snmp的支持:
|
[root@mail src]# tar -jxf courier-imapd-2.2.1.tar.ba2 [root@mail src]# cd courier-imapd-2.2.1
[root@mail courier-imapd-2.2.1]# ./configure --with-redhat \ > --disable-root-check --enable-unicode=utf-8,iso-8859-1,gb2312 \ > --with-trashquota --with-dirsync
[root@mail courier-imapd-2.2.1]# make [root@mail courier-imapd-2.2.1]# make install-strip [root@mail courier-imapd-2.2.1]# make install-configure [root@mail courier-imapd-2.2.1]# cp courier-imap.sysvinit /etc/rc.d/init.d/courier-imap [root@mail courier-imapd-2.2.1]# chmod 755 /etc/rc.d/init.d/courier-imap [root@mail courier-imapd-2.2.1]# chkconfig --level 0123456 courier-imap on |
8.3. 配置
修改courier-imap的认证配置文件/usr/lib/courier-imap/etc/authdaemonrc:
|
[root@mail courier-imapd-2.2.1]# cd /usr/lib/courier-imap/etc [root@mail etc]# vi authdaemonrc |
内容如下,确保只使用mysql认证模块:
|
authmodulelist="authmysql" |
然后修改mysql认证模块的配置文件:
|
[root@mail etc]# vi authmysqlrc |
内容如下:
|
mysql_server localhost |
编辑imap的配置文件imapd,使其自动启动:
|
[root@mail etc]# vi imapd |
修改其最后一行为yes:
|
imapdstart=yes |
编辑pop3的配置文件pop3d,使其自动启动:
|
[root@mail etc]# vi pop3d |
修改其最后一行为yes:
|
pop3dstart=yes |
8.4. 运行
启动courier-imap,启动命令如下:
|
[root@mail etc]# /etc/rc.d/init.d/courier-imap start |
courier-imap的认证进程会自动运行。
8.5. 测试courier-imap
启动courier-imap后,首先检查日志/var/log/messages和/var/log/imapd.log有无错误信息,然后检查进程,应该有如下进程存在:
|
[root@mail etc]# pstree |grep authdaemond
|-authdaemond.mys---5*[authdaemond.mys] [root@mail etc]# pstree |grep courier
|-2*[courierlogger] |-2*[couriertcpd] |
接着检查端口,应该有如下端口打开:
|
[root@mail etc]# netstat -an |grep listen
tcp00 0.0.0.0:1100.0.0.0:*listen tcp00 0.0.0.0:1430.0.0.0:*listen |
现在创建邮箱。
|
[root@mail etc]# mkdir /data [root@mail etc]# chown maildrop:maildrop /data [root@mail etc]# su -s/bin/bash maildrop bash-2.05b$ cd /data bash-2.05b$ mkdir trueuser bash-2.05b$ /usr/local/bin/maildirmake trueuser/maildir bash-2.05b$ mkdir -p cngnu.org/virtualuser bash-2.05b$ /usr/local/bin/maildirmake cngnu.org/virtualuser/maildir |
再检测pop3和imap服务:
|
[root@mail etc]# telnet localhost 110 +ok hello there user virtualuser@cngnu.org +ok password required. pass testpw +ok logged in. quit +ok bye-bye |
9. 安装imp
9.1. 下载
http://www.horde.org/horde/
http://www.horde.org/imp/3.2.2/
http://www.horde.org/turba/
|
[root@mail etc]# cd /usr/src [root@mail src]# wget ftp://ftp.horde.org/pub/horde/horde-2.2.4.tar.gz [root@mail src]# wget ftp://ftp.horde.org/pub/pear/pear-1.1.tar.gz [root@mail src]# wget ftp://ftp.horde.org/pub/imp/imp-3.2.2.tar.gz [root@mail src]# wget ftp://ftp.horde.org/pub/turba/turba-1.2.1.tar.gz |
9.2. 配置apache与php
imp对php的环境要求较高。所以通常需要升级php包,并安装由horde定制后的pear包。
修改/etc/php.ini,将register_globals功能打开。
|
register_globals = on |
安装pear包,在as3中,它位于/usr/share/pear下:
|
[root@mail src]# tar zxf /usr/src/pear-1.1.tar.gz [root@mail lib]# cd /usr/share [root@mail lib]# /bin/cp -rf /usr/src/pear/* pear |
最后重新启动apache:
|
[root@mail lib]# chkconfig --level 0123456 httpd on [root@mail lib]# /etc/rc.d/init.d/httpd restart |
9.3. 配置horde
安装horde:
|
[root@mail lib]# cd /var/www/html [root@mail html]# tar zxf /usr/src/horde-2.2.4.tar.gz [root@mail html]# mv horde-2.2.4 horde [root@mail html]# cd horde/scripts/db
[root@mail db]# mysql < mysql_create.sql
[root@mail db]# cd ../../config [root@mail config]# for foo in *.dist; do cp $foo `basename $foo .dist`;done |
然后修改config目录下面的horde.php。
|
[root@mail config]# vi horde.php |
修改162行:
|
$conf[prefs][driver] = none; |
为:
|
$conf[prefs][driver] = sql; |
修改171行至176行,将其注释去掉并写入horde数据库的口令:
|
// $conf[prefs][params][phptype] = mysql; |
为:
|
$conf[prefs][params][phptype] = mysql; |
这里我们没有修改horde数据库的默认的数据库设置,如果在实际使用中,至少应该取一个比较复杂的密码。
再来修改config目录下面的registry.php。
, ,|
[root@mail config]# vi registry.php |
修改23行至24行,将其注释去掉:
|
// $this->registry[auth][login] = imp; |
为:
|
$this->registry[auth][login] = imp; |
然后修改119、138行激活imp和turba:
|
status => inactive |
为:
|
status => active |
最后在浏览器中访问如下url测试horde需要的环境是否满足:
|
http://你的邮件服务器的ip/horde/test.php |
如果发现有红色的提示,可能需要修改你的php的安装和配置(参见上一节),然后再重新测试。
9.4. 配置imp
安装imp:
|
[root@mail config]# cd .. [root@mail horde]# tar zxf /usr/src/imp-3.2.2.tar.gz [root@mail horde]# mv imp-3.2.2 imp [root@mail horde]# cd imp/config [root@mail config]# for foo in *.dist; do cp $foo `basename $foo .dist`;done |
然后修改config目录里面的conf.php:
|
[root@mail config]# vi conf.php |
修改37行:
|
$conf[menu][apps] = array(); |
为:
|
$conf[menu][apps] = array(turba); |
修改57行:
|
$conf[user][allow_resume_all] = false; |
为:
|
$conf[user][allow_resume_all] = true; |
修改63行:
|
$conf[user][allow_resume_all_in_drafts] = false; |
为:
|
$conf[user][allow_resume_all_in_drafts] = true; |
然后修改prefs.php:
|
[root@mail config]# vi prefs.php |
将自动维护功能关闭,修改426、427行:
|
value => 1, |
为:
|
value => 0, |
再注释773行:
|
value => , |
为:
|
//value => , |
取消注释774行:
|
// value => localsql, |
为:
|
value => localsql, |
最后修改servers.php:
|
[root@mail config]# vi servers.php |
注释除“cyrus”服务器外的所有服务器配置,然后修改“cyrus”服务器的配置为:
|
$servers[cyrus] = array( |
9.5. 配置turba
安装turba:
|
[root@mail config]# cd ../.. [root@mail horde]# tar zxf /usr/src/turba-1.2.1.tar.gz [root@mail horde]# mv turba-1.2.1 turba [root@mail horde]# cd turba/config [root@mail config]# for foo in *.dist; do cp $foo `basename $foo .dist`;done |
然后修改config目录里面的conf.php:
|
[root@mail config]# vi conf.php |
修改32行:
|
$conf[menu][apps] = array(); |
为:
|
$conf[menu][apps] = array(imp); |
然后修改config目录里面的sources.php:
|
[root@mail config]# vi sources.php |
修改146行:
|
password => *****; |
为:
|
password => horde; |
最后,添加turba数据库表:
|
[root@mail config]# cd ../scripts/drivers [root@mail config]# mysql horde <turba.sql |
9.6. 测试imp
最后在浏览器中访问如下url:
|
http://你的邮件服务器的ip/horde/ |
输入用户名virtualuser@cngnu.org和密码testpw登录(或trueuser)。
10. 其他
10.1. 启动脚本
courier-imap已经有了启动脚本,只需要为postfix编写一个启动脚本postfix即可:
#!/bin/bash
#
# mailsys this shell script takes care of starting and stopping postfix
# author : xingyu.wang <wxy@cngnu.org> 2004/1/28
#
# chkconfig: 2345 80 30
# description: postfix is a mail transport agent, which is the program
# that moves mail from one machine to another.
#
# processname: mailsys
# pidfile: /var/run/postfix.pid
# source function library.
. /etc/rc.d/init.d/functions
# source networking configuration.
. /etc/sysconfig/network
# check that networking is up.
[ ${networking} = "no" ] && exit 0
[ -f /usr/sbin/postfix ] || exit 0
retval=0
prog="postfix"
start() {
# start daemons.
echo -n $"starting $prog: "
/usr/sbin/postfix start > /dev/null 2>&1 &
retval=$?
if [ $retval -eq 0 ]; then
touch /var/lock/subsys/postfix
success $"$prog start"
else
failure $"$prog start failure"
fi
echo
return $retval
}
stop() {
# stop daemons.
echo -n $"shutting down $prog: "
/usr/sbin/postfix stop > /dev/null 2>&1 &
retval=$?
if [ $retval -eq 0 ]; then
rm -f /var/lock/subsys/postfix
success $"$prog stop"
else
failure $"$prog stop failure"
fi
echo
return $retval
}
# see how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
start
retval=$?
;;
*)
echo $"usage: $0 {start|stop|restart}"
exit 1
esac
exit $retval
|
|
[root@mail root]# chmod 755 /etc/rc.d/init.d/postfix [root@mail root]# chkconfig --level 0123456 postfix on [root@mail root]# chkconfig --level 0123456 sendmail off |
10.2. 整体测试
创建邮箱后,测试发信功能:
|
[root@mail root]# mail trueuser subject: test by me this is a test. . cc: [root@mail root]# mailq mail queue is empty [root@mail root]# tail /var/log/maillog
|
使用mailq来查看邮件队列是否有错误,并查看/var/log/maillog是否有错误信息。如果一切正常,说明信件已经发送到trueuser了。
测试收信,先测试pop3:
|
[root@mail root]# telnet localhost 110 +ok hello there user trueuser +ok password required. pass testpw +ok logged in. list 1 400 top 1 10 return-path: <root@cngnu.org> this is a test. . quit +ok |
最后测试imp,在浏览器中访问如下url:
|
http://你的imp服务器的ip/horde/ |
输入用户名trueuser和密码testpw登录。
你也可以使用任何其它的邮件客户端程序来测试,如kmail、outlook express等等。
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!


