Postfix + Cyrus-IMAP + Cyrus-SASL + MySQL + IMP完全指南
2015-05-13 21:11
417 查看
CNGNU Postfix邮件系统系列指南之一
Postfix + Cyrus-IMAP + Cyrus-SASL + MySQL + IMP完全指南
CNGNU Postfix邮件系统系列指南之二
Postfix + Courier-IMAP + Cyrus-SASL + MySQL + IMP
完全指南
作者:王兴宇 <wxy@cngnu.org>版本:0.21
版权:GPL
发布日期:2004-02-04
目录
1. 概述1.1. 目的
1.2. 更新历史
1.3. TODO
1.4. 鸣谢
2. 系统功能
3. 系统基本前提
4. 配置MySQL
4.1. 运行
4.2. 测试
4.3. 配置
5. 安装pam_mysql
5.1. 下载
5.2. 编译与安装
5.3. 配置
6. 安装Cyrus-SASL
6.1. 下载
6.2. 编译与安装
6.3. 配置
6.4. 运行
7. 安装Postfix
7.1. 下载
7.2. 编译与安装
7.3. 配置
7.4. 运行
7.5. 测试
8. 安装Cyrus-IMAP
8.1. 下载
8.2. 编译与安装
8.3. 配置
8.4. 运行
8.5. 测试
9. 安装IMP
9.1. 下载
9.2. 配置Apache/PHP
9.3. 配置Horde
9.4. 配置Imp
9.5. 配置Turba
9.6. 测试IMP
10. 其它
10.1. 启动脚本
10.2. 整体测试
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。2004-02-04 修正了一些笔误。
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 --rebuild 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 |
[root@mail i386]# cd [root@mail root]# vi /etc/my.cnf |
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 tcp??0??0 127.0.0.1:3306??0.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 ( ID int(10) unsigned NOT NULL auto_increment, USERNAME varchar(128) NOT NULL default '', PASSWORD varchar(40) NOT NULL default '', CLEAR_PASSWORD varchar(40) NOT NULL default '', FORWARD varchar(128) NOT NULL default '', DOMAIN varchar(64) NOT NULL default '', HOMEDIR varchar(128) NOT NULL default '', MAILDIR varchar(128) NOT NULL default '', MAIL varchar(64) NOT NULL default '', GID int(11) NOT NULL default 450, UID int(11) NOT NULL default 450, FILTER varchar(64) NOT NULL default 'OK', QUOTA int(11) NOT NULL default '10485760', STATUS tinyint(4) NOT NULL default '1', PRIMARY KEY (ID), UNIQUE KEY USERNAME (USERNAME), UNIQUE KEY MAIL (MAIL) ) TYPE=MyISAM; INSERT INTO USER (USERNAME,PASSWORD,CLEAR_PASSWORD, FORWARD,DOMAIN,HOMEDIR,MAILDIR,MAIL) VALUES ('trueuser','$1$pi.WVgBx$a3dUCzBnbY76jnZlqWQCQ/','testpw', 'trueuser','cngnu.org','/data/mail/trueuser','/data/mail/trueuser/Maildir', 'trueuser@cngnu.org'), ('virtualuser@cngnu.org','$1$pi.WVgBx$a3dUCzBnbY76jnZlqWQCQ/','testpw', 'virtualuser@cngnu.org','cngnu.org','/data/mail/cngnu.org/virtualuser', '/data/mail/cngnu.org/virtualuser/Maildir','virtualuser@cngnu.org'); |
[root@mail root]# mysql < mail.sql |
非虚拟域邮箱“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 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 |
[root@mail src]# cd redhat/SPECS [root@mail SPECS]# patch -p0 < ../../cyrus-sasl.spec.patch |
[root@mail SPECS]# rpmbuild -bb cyrus-sasl.spec |
[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 |
??整个系统只有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 |
[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 port 3306 socket /var/lib/mysql/mysql.sock database mail dbuser mail dbpw secret dbtable USER default_uidnumber 450 default_gidnumner 450 uid_field MAIL uidnumber_field UID gidnumber_field GID maildir_field MAILDIR homedirectory_field HOMEDIR quota_field QUOTA mailstatus_field STATUS where_clause "" |
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/newaliases /usr/bin/newaliases.orig [root@mail src]# mv /usr/bin/mailq /usr/bin/mailq.orig [root@mail src]# mv /usr/sbin/sendmail /usr/sbin/sendmail.orig |
[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 |
??编译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 /etc/postfix [root@mail postfix]# echo 'root: virtualuser@cngnu.org' >> /etc/postfix/aliases |
[root@mail postfix]# postalias /etc/postfix/aliases |
[root@mail postfix]# postmap 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} |
[root@mail postfix]# vi 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 = permit_mynetworks, permit_sasl_authenticated, check_recipient_access mysql:/etc/postfix/filter.mysql, reject_invalid_hostname, reject_non_fqdn_hostname, reject_unknown_sender_domain, reject_non_fqdn_sender, reject_non_fqdn_recipient, reject_unknown_recipient_domain, reject_unauth_pipelining, reject_unauth_destination, permit |
通过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.mysql |
# # 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 |
7.5. 测试Postfix
??启动Postfix后,首先检查日志/var/log/messages有无错误信息,然后检查进程,应该有如下进程存在:检查端口及进程:[root@mail postfix]# pstree |grep master |-master-+-pickup |
[root@mail postfix]# netstat -an |grep LISTEN tcp??0??0 0.0.0.0:25??0.0.0.0:*??LISTEN |
[root@mail postfix]# telnet localhost 25 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. 220 mail.cngnu.org ESMTP Postfix QUIT 221 Bye Connection closed by foreign host. |
??PLAIN认证方式:
[root@mail postfix]# perl -MMIME::Base64 -e > 'print encode_base64("virtualuser@cngnu.org00virtualuser@cngnu.org00testpw");' dmlydHVhbHVzZXJAY25nbnUub3JnAHZpcnR1YWx1c2VyQGNuZ251Lm9yZwB0ZXN0cHc= [root@mail postfix]# telnet localhost 25 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. 220 mail.cngnu.org ESMTP Postfix 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("trueuser00trueuser00testpw");' dHJ1ZXVzZXIAdHJ1ZXVzZXIAdGVzdHB3 |
[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... Connected to localhost. Escape character is '^]'. 220 mail.cngnu.org ESMTP Postfix 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 |
??这里使用Perl里面的MIME::Base64模块(如果需要安装:perl -MCPAN -e 'install MIME::Base64;')来取得这个验证串:perl -MMIME::Base64 -e 'print base64_encode("用户名00用户名00密码");'来得到MIME-Base64编码的验证串(“00”是八进制的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 |
authmodulelist="authmysql" authmodulelistorig="authmysql" version="authdaemond.mysql" |
[root@mail etc]# vi authmysqlrc |
MYSQL_SERVER localhost MYSQL_USERNAME mail MYSQL_PASSWORD secret MYSQL_SOCKET /var/lib/mysql/mysql.sock MYSQL_PORT 3306 MYSQL_DATABASE mail MYSQL_USER_TABLE USER MYSQL_CRYPT_PWFIELD PASSWORD MYSQL_CLEAR_PWFIELD CLEAR_PASSWORD MYSQL_UID_FIELD UID MYSQL_GID_FIELD GID MYSQL_LOGIN_FIELD USERNAME MYSQL_HOME_FIELD HOMEDIR MYSQL_NAME_FIELD USERNAME MYSQL_MAILDIR_FIELD MAILDIR MYSQL_QUOTA_FIELD QUOTA MYSQL_WHERE_CLAUSE STATUS=1 |
[root@mail etc]# vi imapd |
IMAPDSTART=YES |
[root@mail etc]# vi pop3d |
POP3DSTART=YES |
8.4. 运行
??启动Courier-IMAP,启动命令如下:[root@mail etc]# /etc/rc.d/init.d/courier-imap start |
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 tcp??0??0 0.0.0.0:110??0.0.0.0:*??LISTEN tcp??0??0 0.0.0.0:143??0.0.0.0:*??LISTEN |
[root@mail etc]# mkdir -p /data/mail [root@mail etc]# chown maildrop:maildrop /data/mail [root@mail etc]# su -s/bin/bash maildrop bash-2.05b$ cd /data/mail 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 |
[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 |
[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 |
[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 |
[root@mail config]# vi horde.php |
$conf['prefs']['driver'] = 'none'; |
$conf['prefs']['driver'] = 'sql'; |
// $conf['prefs']['params']['phptype'] = 'mysql'; // $conf['prefs']['params']['hostspec'] = 'localhost'; // $conf['prefs']['params']['username'] = 'horde'; // $conf['prefs']['params']['password'] = '*****'; // $conf['prefs']['params']['database'] = 'horde'; // $conf['prefs']['params']['table'] = 'horde_prefs'; |
$conf['prefs']['params']['phptype'] = 'mysql'; $conf['prefs']['params']['hostspec'] = 'localhost'; $conf['prefs']['params']['username'] = 'horde'; $conf['prefs']['params']['password'] = 'horde'; $conf['prefs']['params']['database'] = 'horde'; $conf['prefs']['params']['table'] = 'horde_prefs'; |
??再来修改config目录下面的registry.php。
[root@mail config]# vi registry.php |
// $this->registry['auth']['login'] = 'imp'; // $this->registry['auth']['logout'] = 'imp'; |
$this->registry['auth']['login'] = 'imp'; $this->registry['auth']['logout'] = 'imp'; |
'status' => 'inactive' |
'status' => 'active' |
http://你的邮件服务器的IP/horde/test.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 |
[root@mail config]# vi conf.php |
$conf['menu']['apps'] = array(); |
$conf['menu']['apps'] = array('turba'); |
$conf['user']['allow_resume_all'] = false; |
$conf['user']['allow_resume_all'] = true; |
$conf['user']['allow_resume_all_in_drafts'] = false; |
$conf['user']['allow_resume_all_in_drafts'] = true; |
[root@mail config]# vi prefs.php |
'value' => 1, 'locked' => false, |
'value' => 0, 'locked' => true, |
'value' => '', |
//'value' => '', |
// 'value' => 'localsql', |
'value' => 'localsql', |
[root@mail config]# vi servers.php |
$servers['cyrus'] = array( 'name' => 'IMAP Server', 'server' => 'localhost', 'protocol' => 'imap/notls', 'port' => 143, 'folders' => 'mail/', 'namespace' => '', 'maildomain' => 'cngnu.org', 'smtphost' => 'mail.cngnu.org', 'realm' => 'cngnu.org', 'preferred' => '' ); |
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 |
[root@mail config]# vi conf.php |
$conf['menu']['apps'] = array(); |
$conf['menu']['apps'] = array('imp'); |
[root@mail config]# vi sources.php |
'password' => '*****'; |
'password' => 'horde'; |
[root@mail config]# cd ../scripts/drivers [root@mail config]# mysql horde <turba.sql |
9.6. 测试IMP
??最后在浏览器中访问如下URL:http://你的邮件服务器的IP/horde/ |
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 |
??测试收信,先测试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> Delivered-To: <trueuser@cngnu.org> Received: by mail.cngnu.org (Postfix, from userid 0) id 6A7C4CCCF; Mon, 26 Jan 2004 21:27:23 +0800 (CST) To: trueuser@cngnu.org Subject: test by me Message-Id: <20040126212723.6A7C4CCCF@mail.cngnu.org> Date: Mon, 26 Jan 2004 21:27:23 +0800 (CST) From: root@cngnu.org (root) this is a test. . QUIT +OK |
http://你的IMP服务器的IP/horde/ |
??你也可以使用任何其它的邮件客户端程序来测试,如kmail、Outlook Express等等。
??OK,到此为止,我们的邮件系统就架设完毕了。如果有任何问题,请到论坛http://www.anti-spam.org.cn/forum/的mail版讨论。
相关文章推荐
- Postfix + Cyrus-IMAP + Cyrus-SASL + MySQL + IMP 完全指南
- Postfix + Cyrus-IMAP + Cyrus-SASL + MySQL + IMP 完全指南
- Postfix + Courier-IMAP + Cyrus-SASL + MySQL + IMP完全指南
- Postfix + Cyrus-IMAP + Cyrus-SASL + MySQL + IMP 完全指南
- CNGNU Postfix邮件系统系列指南之一 Postfix + Cyrus-IMAP + Cyrus-SASL + MySQL + IMP
- Postfix + Cyrus-IMAP + Cyrus-SASL + MySQL + IMP
- Postfix + Cyrus-IMAP + Cyrus-SASL + MySQL + IMP
- Postfix + Cyrus-IMAP + Cyrus-SASL + MySQL + IMP
- Postfix + Cyrus-IMAP + Cyrus-SASL + MySQL + IMP
- Postfix集成环境(Postfix + MySQL + Cyrus-sasl2 + Courier-imap + iGENUS + Postfixadmin)
- postfix+cyrus sasl+mysql+cyrus imap +extmail on linux centos 3.8
- FreeBSD7.1+postfix+sasl2+mysql+maildrop+ExtMan+Mailman+ClamAv完全安装
- FreeBSD7.0+postfix+sasl2+mysql+maildrop+ExtMan+Mailman+ClamAv完全安装
- postfix courier-imap maildrop cyrus-sasl extman搭建mail服务器
- CentOS+postfix+ExtMail+amavisd-new+Spam_Locker+DSpam配置指南:九、配置Cyrus-SASL
- courier-authlib、courier-imap、maildrop、cyrus-sasl的编译安装及与postfix的关联
- Postfix邮件系统安装与配置:Postfix,Cyrus-IMAP,Cyrus-sasl,Dovecot和SPF
- redhat9+postfix+cyrus-sasl+mysql+postfixadmin+courier-imap+courier-maildrop+squirrelmail(courier-sqwebmail openwebmail)+clamav+s
- postfix + cyrus-sasl2 + courier-authlib + Courier-IMAP + postfixadmin
- Postfix-courier-authlib-cyrus-sasl-courier-imap-maildrop-extmail-extman源码安装