热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Postfix+Courier-IMAP+Cyrus-SASL+MySQL+IMP安装配置详解

目录1.概述1.1.目的1.2.更新历史1.3.TODO1.4.鸣谢2.系统功能3.系统基本前提4.配置MySQL4.1.运行4.2.测试4.3.配置5.安装pam_mysql5.1.下载5.2.编译与安装5.3.配置6.安装Cyrus-SASL6.1.下载6.2.编译与安装6.3.配置6.4.
目录

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. 目的

  本文试图介绍如何在一个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. 鸣谢

  系统逻辑结构:

+--------------------------------------------------------------+
|                                                              |
|  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://c

Postfix + Courier-IMAP + Cyrus-SASL + MySQL + IMP第2部分:

ngnu.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/来读取信件。

  本文以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.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

  为提高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

tcp  0  0 127.0.0.1:3306  0.0.0.0:*  LISTEN

  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,

Postfix + Courier-IMAP + Cyrus-SASL + MySQL + IMP第3部分:

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','$pi.WVgBx$a3dUCzBnbY76jnZlqWQCQ/','testpw',

'trueuser','cngnu.org','/data/mail/trueuser','/data/mail/trueuser/Maildir',

'trueuser@cngnu.org'),
('virtualuser@cngnu.org','$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

  在MySQL中创建邮件用户数据库,并添加两个测试邮箱:

非虚拟域邮箱“trueuser”,密码是“testpw”

虚拟域邮箱“virtualuser@cngnu.org”,密码是“testpw”

  上面的mail数据库的USER表用来保存用户信息:

USERNAME是用户名。USERNAME不但作为认证的字段,而且是本地邮箱查找条件(见下面的Postfix的virtual.mysql)。这里采用了加密密码是为了更好的安全性。对于

非虚拟域邮箱:USERNAME字段是邮件的本地部分(“@”前面的部分)

虚拟域邮箱:USERNAME字段是邮件地址全称

PASSWORD字段是邮箱的MD5-Crypt密码,CLEAR_PASSWORD是明文密码。邮箱的密码是“testpw”,加密后的(MD5-CRYPT)密文是“$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.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-s

Postfix + Courier-IMAP + Cyrus-SASL + MySQL + IMP第4部分:

asl.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-%.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-%.tar.gz
***************
*** 73,78 ****
--- 73,87 ----
The %-md5 package contains the Cyrus SASL plugins which support
CRAM-MD5 and DIGEST-MD5 authentication schemes.
+ %package mysql
+ Requires: % = %-%
+ Group: System Environment/Libraries
+ Summary: Mysql support for Cyrus SASL.
+
+ %description mysql
+ The %-mysql package contains the Cyrus SASL plugins which support
+ Mysql auxprop authentication schemes.
+
%prep
%setup -q -c -a 2
pushd cyrus-sasl-%
***************
*** 167,173 ****
--enable-cram
--enable-digest
--enable-plain
! --enable-login
# --enable-auth-sasldb -- EXPERIMENTAL
make sasldir=%
popd
--- 176,183 ----
--enable-cram
--enable-digest
--enable-plain
! --enable-login
! --with-mysql
# --enable-auth-sasldb -- EXPERIMENTAL
make sasldir=%
popd
***************
*** 273,278 ****
--- 283,293 ----
%/*digestmd5*.so*
%/*digestmd5*.la
+ %files mysql
+ %defattr(-,root,root)
+ %/*mysql*.so*
+ %/*mysql*.la
+
%files gssapi
%defattr(-,root,root)
%/*gssapi*.so*
***************
*** 300,305 ****
--- 315,321 ----
%/*anonymous*.a
%/*crammd5*.a
%/*digestmd5*.a
+ %/*mysql*.a
%/*gssapi*.a
%/*login*.a
%/*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

Postfix + Courier-IMAP + Cyrus-SASL + MySQL + IMP第5部分:

-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.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
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.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/

Postfix + Courier-IMAP + Cyrus-SASL + MySQL + IMP第6部分:

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

  然后添加两个组: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 /etc/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 $

  修改为:

maildrop unix - n n - - pipe
flags=DRhu user=maildrop argv=/usr/local/bin/maildrop -d $

  这里要把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.mys

Postfix + Courier-IMAP + Cyrus-SASL + MySQL + IMP第7部分:

ql

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

  如果希望支持更多的虚拟域,可以在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.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

  可以使用文末所附脚本设置postfix在系统启动时候自动运行。

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

  再检测SMTP服务是否

Postfix + Courier-IMAP + Cyrus-SASL + MySQL + IMP第8部分:

正常:

[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.

  使用如下命令测试postfix的SMTP的认证(这里仅测试了“virtualuser@cngnu.org”,“trueuser”请自行测试):

  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

  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...
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

Postfix + Courier-IMAP + Cyrus-SASL + MySQL + IMP第9部分:

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 'installMIME::Base64;')来取得这个验证串:perl -MMIME::Base64 -e 'printbase64_encode("用户名00用户名00密码");'来得到MIME-Base64编码的验证串(“00”是八进制的ASCII(0)字符)。此外,你也可以使用mmencode来生成,mmencode可以在metamail这个包里面找到。

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"
authmodulelistorig="authmysql"
version="authdaemond.mysql"

  然后修改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

Postfix + Courier-IMAP + Cyrus-SASL + MySQL + IMP第10部分:

_FIELD USERNAME
MYSQL_HOME_FIELD HOMEDIR
MYSQL_NAME_FIELD USERNAME
MYSQL_MAILDIR_FIELD MAILDIR
MYSQL_QUOTA_FIELD QUOTA
MYSQL_WHERE_CLAUSE STATUS=1

  编辑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

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

  再检测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.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:

Postfix + Courier-IMAP + Cyrus-SASL + MySQL + IMP第12部分:

>[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

[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']['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';

  这里我们没有修改horde数据库的默认的数据库设置,如果在实际使用中,至少应该取一个比较复杂的密码。

  再来修改config目录下面的registry.php。

[root@mail config]# vi registry.php

  修改23行至24行,将其注释去掉:

// $this->registry['auth']['login'] = 'imp';
// $this->registry['auth']['logout'] = 'imp';

  为:

$this->registry['auth']['login'] = 'imp';
$this->registry['auth']['logout'] = '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

  修改3

Postfix + Courier-IMAP + Cyrus-SASL + MySQL + IMP第4部分:

7行:

$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,
'locked' => false,

  为:

'value' => 0,
'locked' => true,

  再注释773行:

'value' => '',

  为:

//'value' => '',

  取消注释774行:

// 'value' => 'localsql',

  为:

'value' => 'localsql',

  最后修改servers.php:

[root@mail config]# vi servers.php

  注释除“cyrus”服务器外的所有服务器配置,然后修改“cyrus”服务器的配置为:

$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

  然后修改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

9.6. 测试IMP

  最后在浏览器中访问如下URL:

http://你的邮件服务器的IP/horde/

  输入用户名virtualuser@cngnu.org和密码testpw登录(或trueuser)。

10.1. 启动脚本

  Courier-IMAP已经有了启动脚本,只需要为Postfix编写一个启动脚本postfix即可:

#!/bin/bash
#
# mailsys This shell script takes care of starting and stopping Postfix 
# author : x
Postfix + Courier-IMAP + Cyrus-SASL + MySQL + IMP第5部分:    ingyu.wang  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.
[ $ = "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 "" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
start
RETVAL=$?
;;
*)
echo $"Usage:  "
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:


推荐阅读
  • 本文介绍了在开发Android新闻App时,搭建本地服务器的步骤。通过使用XAMPP软件,可以一键式搭建起开发环境,包括Apache、MySQL、PHP、PERL。在本地服务器上新建数据库和表,并设置相应的属性。最后,给出了创建new表的SQL语句。这个教程适合初学者参考。 ... [详细]
  • 如何实现织梦DedeCms全站伪静态
    本文介绍了如何通过修改织梦DedeCms源代码来实现全站伪静态,以提高管理和SEO效果。全站伪静态可以避免重复URL的问题,同时通过使用mod_rewrite伪静态模块和.htaccess正则表达式,可以更好地适应搜索引擎的需求。文章还提到了一些相关的技术和工具,如Ubuntu、qt编程、tomcat端口、爬虫、php request根目录等。 ... [详细]
  • 目录浏览漏洞与目录遍历漏洞的危害及修复方法
    本文讨论了目录浏览漏洞与目录遍历漏洞的危害,包括网站结构暴露、隐秘文件访问等。同时介绍了检测方法,如使用漏洞扫描器和搜索关键词。最后提供了针对常见中间件的修复方式,包括关闭目录浏览功能。对于保护网站安全具有一定的参考价值。 ... [详细]
  • Nginx使用AWStats日志分析的步骤及注意事项
    本文介绍了在Centos7操作系统上使用Nginx和AWStats进行日志分析的步骤和注意事项。通过AWStats可以统计网站的访问量、IP地址、操作系统、浏览器等信息,并提供精确到每月、每日、每小时的数据。在部署AWStats之前需要确认服务器上已经安装了Perl环境,并进行DNS解析。 ... [详细]
  • 本文介绍了Python高级网络编程及TCP/IP协议簇的OSI七层模型。首先简单介绍了七层模型的各层及其封装解封装过程。然后讨论了程序开发中涉及到的网络通信内容,主要包括TCP协议、UDP协议和IPV4协议。最后还介绍了socket编程、聊天socket实现、远程执行命令、上传文件、socketserver及其源码分析等相关内容。 ... [详细]
  • 这是原文链接:sendingformdata许多情况下,我们使用表单发送数据到服务器。服务器处理数据并返回响应给用户。这看起来很简单,但是 ... [详细]
  • 本文介绍了在Mac上搭建php环境后无法使用localhost连接mysql的问题,并通过将localhost替换为127.0.0.1或本机IP解决了该问题。文章解释了localhost和127.0.0.1的区别,指出了使用socket方式连接导致连接失败的原因。此外,还提供了相关链接供读者深入了解。 ... [详细]
  • mac php错误日志配置方法及错误级别修改
    本文介绍了在mac环境下配置php错误日志的方法,包括修改php.ini文件和httpd.conf文件的操作步骤。同时还介绍了如何修改错误级别,以及相应的错误级别参考链接。 ... [详细]
  • 如何提高PHP编程技能及推荐高级教程
    本文介绍了如何提高PHP编程技能的方法,推荐了一些高级教程。学习任何一种编程语言都需要长期的坚持和不懈的努力,本文提醒读者要有足够的耐心和时间投入。通过实践操作学习,可以更好地理解和掌握PHP语言的特异性,特别是单引号和双引号的用法。同时,本文也指出了只走马观花看整体而不深入学习的学习方式无法真正掌握这门语言,建议读者要从整体来考虑局部,培养大局观。最后,本文提醒读者完成一个像模像样的网站需要付出更多的努力和实践。 ... [详细]
  • 腾讯安全平台部招聘安全工程师和数据分析工程师
    腾讯安全平台部正在招聘安全工程师和数据分析工程师。安全工程师负责安全问题和安全事件的跟踪和分析,提供安全测试技术支持;数据分析工程师负责安全产品相关系统数据统计和分析挖掘,通过用户行为数据建模为业务决策提供参考。招聘要求包括熟悉渗透测试和常见安全工具原理,精通Web漏洞,熟练使用多门编程语言等。有相关工作经验和在安全站点发表作品的候选人优先考虑。 ... [详细]
  • 本文讨论了Alink回归预测的不完善问题,指出目前主要针对Python做案例,对其他语言支持不足。同时介绍了pom.xml文件的基本结构和使用方法,以及Maven的相关知识。最后,对Alink回归预测的未来发展提出了期待。 ... [详细]
  • 本文介绍了如何使用php限制数据库插入的条数并显示每次插入数据库之间的数据数目,以及避免重复提交的方法。同时还介绍了如何限制某一个数据库用户的并发连接数,以及设置数据库的连接数和连接超时时间的方法。最后提供了一些关于浏览器在线用户数和数据库连接数量比例的参考值。 ... [详细]
  • 本文介绍了使用PHP实现断点续传乱序合并文件的方法和源码。由于网络原因,文件需要分割成多个部分发送,因此无法按顺序接收。文章中提供了merge2.php的源码,通过使用shuffle函数打乱文件读取顺序,实现了乱序合并文件的功能。同时,还介绍了filesize、glob、unlink、fopen等相关函数的使用。阅读本文可以了解如何使用PHP实现断点续传乱序合并文件的具体步骤。 ... [详细]
  • 本文介绍了在Linux下安装Perl的步骤,并提供了一个简单的Perl程序示例。同时,还展示了运行该程序的结果。 ... [详细]
  • 高质量SQL书写的30条建议
    本文提供了30条关于优化SQL的建议,包括避免使用select *,使用具体字段,以及使用limit 1等。这些建议是基于实际开发经验总结出来的,旨在帮助读者优化SQL查询。 ... [详细]
author-avatar
手机用户2502938137
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有