Extmail搭建



目录

一、背景介绍............1

二、实战演练............1

2.1 操作系统安装............1

2.2 制作YUM仓库............1

2.3 配置MTA-postfix............1

2.3.1 安装postfix............1

2.3.2 配置postfix............1

2.4 配置Courier-Authlib............2

2.4.1 安装Courier-Authlib............2

2.4.2 配置Courier-Authlib............2

2.5 配置Maildrop............3

2.5.1 安装Maildrop............3

2.5.2 配置Maildrop............3

2.5.3 测试maildrop对authlib支持............4

2.6 配置Apache............4

2.7 配置Webmail-ExtMail............5

2.7.1 安装ExtMail............5

2.7.2 编辑webmail.cf............5

2.8 配置管理后台-ExtMan............5

2.8.1 yum安装ExtMan............5

2.8.2 数据库初始化............5

2.8.3 设置虚拟域和虚拟用户的配置文件............6

2.8.4 测试authlib............6

2.8.5 配置图形化日志............7

2.9 配置Cyrus-SASL............7

2.9.1 安装cyrus-sasl............7

2.9.2 配置main.cf文件............8

2.9.3 编辑smtpd.conf文件............8

2.9.4 测试SMTP认证............9

2.10 配置Courier-IMAP............9

2.10.1 安装Courier-imap............9

2.10.2 测试POP3工作是否正常............10

三、注意事项............10


一、背景介绍

ExtMail Solution 是一个基于优秀开源软件的电子邮件系统解决方案,核心部件包括了PostfixAmavisd-newClamAVExtMailExtManCourier系列软件。是一个功能相对比较齐全的免费电子邮件系统。本次环境中使用的是CentOS

二、实战演练

2.1 操作系统安装

采用系统光盘进行安装,然后按照日常安装步骤依次进行是否校验介质、安装界面语言等选项……注意必须安装MYSQL数据库。

2.2 制作YUM仓库

使用EMOS光盘制作本地 yum仓库,CentOS系统安装完成之后在/etc/yum.repos.d/下会生成4个配置文件。其中CentOS-Media.repo是本地YUM源的配置文件,可以在该配置文件中把EMOS光盘的路径进行添加完成本地YUM源的配置。

2.3 配置MTA-postfix

2.3.1安装postfix

# yum install postfix

# rpm -e sendmail

2.3.2配置postfix

# postconf -n > /etc/postfix/main2.cf

# mv /etc/postfix/main.cf/etc/postfix/main.cf.old

# mv /etc/postfix/main2.cf/etc/postfix/main.cf

# vi /etc/postfix/main.cf(编辑main.cf文件,将文件中标红的字体替换成自己的域名)

增加如下内容,最后保存退出:

# hostname

mynetworks = 127.0.0.1

myhostname = (mail.extmail.orgàmail.test.com)

mydestination = $mynetworks $myhostname

# banner

mail_name = Postfix - by (extmail.orgàtest.com)

smtpd_banner = $myhostname ESMTP $mail_name

# response immediately

smtpd_error_sleep_time = 0s

# Message and return code control

message_size_limit = 5242880

mailbox_size_limit = 5242880

show_user_unknown_table_name = no

# Queue lifetime control

bounce_queue_lifetime = 1d

maximal_queue_lifetime = 1d

设置postfix启动及开机自启:

#service postfix restart

#chkconfig postfix on

2.4 配置Courier-Authlib

2.4.1安装Courier-Authlib

# yum install courier-authlib

# yum install courier-authlib-mysql

2.4.2配置Courier-Authlib

# vi /etc/authlib/authmysqlrc

并将其内容清空,然后增加如下内容,最后保存退出:

MYSQL_SERVER            localhost

MYSQL_USERNAME          extmail

MYSQL_PASSWORD          extmail

MYSQL_SOCKET            /var/lib/mysql/mysql.sock

MYSQL_PORT              3306

MYSQL_OPT               0

MYSQL_DATABASE          extmail

MYSQL_USER_TABLE        mailbox

MYSQL_CRYPT_PWFIELD     password

MYSQL_UID_FIELD         uidnumber

MYSQL_GID_FIELD         gidnumber

MYSQL_LOGIN_FIELD       username

MYSQL_HOME_FIELD        homedir

MYSQL_NAME_FIELD        name

MYSQL_MAILDIR_FIELD     maildir

MYSQL_QUOTA_FIELD       quota

MYSQL_SELECT_CLAUSE     SELECTusername,password,"",uidnumber,gidnumber,\

                  CONCAT('/home/domains/',homedir),               \

                  CONCAT('/home/domains/',maildir),               \

                  quota,                           \                     name                                     \

                FROM mailbox                                \

                  WHERE username ='$(local_part)@$(domain)'

# vi /etc/authlib/authdaemonrc

修改如下内容:

authmodulelist="authmysql"

authmodulelistorig="authmysql"

启动courier-authlib

# service courier-authlib start

如一切正常,命令行将返回如下信息:

Starting Courier authentication services:authdaemond

修改authdaemon socket目录权限,如果该目录权限不正确修改,maildroppostfix等将无法正确获取用户的信息及密码认证:

# chmod 755 /var/spool/authdaemon/

2.5 配置Maildrop

2.5.1安装Maildrop

# yum install maildrop

2.5.2配置Maildrop

配置master.cf 为了使Postfix支持Maildrop,必须修改/etc/postfix/master.cf文件,注释掉maildrop中和图例1结构类似的配置内容,将该语句添加到maildrop配置文件中,注意:flags前面有两个空格wKiom1Y7C4-wnMf_AABS3xOVjVY322.jpg


配置main.cf,由于maildrop不支持一次接收多个收件人,因此必须在main.cf里增加如下参数:

maildrop_destination_recipient_limit = 1

2.5.3测试maildrop对authlib支持

# maildrop –v

看是否出现以下内容:

maildrop 2.1.0 Copyright 1998-2005 DoublePrecision, Inc.

GDBM/DB extensions enabled.

Courier Authentication Library extensionenabled.

Maildir quota extension enabled.

This program is distributed under the termsof the GNU General Public

License. See COPYING for additionalinformation.

注意事项:

1、如需重新编译Maildrop软件包,必须先获得其源码rpm包,并且必须先行安装courier-authlib及其devel软件包,否则编译后的maildrop将无法打开authlib支持。

2maildrop RPM包安装时,会自动创建vuser用户及vgroup用户组,专门用于邮件的存储,vuser:vgroupuid/gid都是1000,这与一般的邮件文档中提及用postfix用户存邮件不一样。因为postfix用户的uid一般都低于500,而Suexec模块编译时对UID/GID的要求是要大于500,因此使用postfix用户不能满足要求。其次,如果用Maildrop作为投递代理(MDA),以postfix身份投递的话,会导致postfix MTA错误。

2.6 配置Apache

# vi /etc/httpd/conf/httpd.conf

在最后一行加上:

NameVirtualHost *:80

Include conf/vhost_*.conf

# vi /etc/httpd/conf/vhost_extmail.conf

里面定义虚拟主机的相关内容(将文件中标红的字体替换成自己的域名)

# VirtualHost for ExtMail Solution

<VirtualHost *:80>

ServerName (mail.extmail.orgàmail.test.com)

DocumentRoot/var/www/extsuite/extmail/html/

ScriptAlias /extmail/cgi//var/www/extsuite/extmail/cgi/

Alias /extmail/var/www/extsuite/extmail/html/

 

ScriptAlias /extman/cgi//var/www/extsuite/extman/cgi/

Alias /extman /var/www/extsuite/extman/html/

 

# Suexec config

SuexecUserGroup vuser vgroup

</VirtualHost>

 

设置apache重启及开机自启


#service httpd restart

# chkconfig httpd on

2.7 配置Webmail-ExtMail

2.7.1安装ExtMail

# yum install extsuite-webmail

2.7.2编辑webmail.cf

# cd /var/www/extsuite/extmail

# cp webmail.cf.default webmail.cf

# vi webmail.cf

主要变动的内容见下:

SYS_MYSQL_USER = extmail

SYS_MYSQL_PASS = extmail

SYS_MYSQL_DB = extmail

更新cgi目录权限由于SuEXEC的需要,必须将extmailcgi目录修改成vuser:vgroup权限:

# chown -R vuser:vgroup/var/www/extsuite/extmail/cgi/

2.8 配置管理后台-ExtMan

2.8.1yum安装ExtMan

# yum install extsuite-webman

 

更新cgi目录权限由于SuEXEC的需要,必须将extmancgi目录修改成vuser:vgroup权限:

# chown -R vuser:vgroup/var/www/extsuite/extman/cgi/

 

链接基本库到Extmail

# mkdir /tmp/extman

# chown -R vuser:vgroup /tmp/extman

2.8.2数据库初始化

启动Mysql且开机自启动

# service mysqld start

# chkconfig mysqld on

导入mysql数据库结构及初始化数据,root密码默认为空

# mysql -u root -p </var/www/extsuite/extman/docs/extmail.sql

# mysql -u root -p </var/www/extsuite/extman/docs/init.sql

备注1上述导入初始化SQL时,默认的uidnumber/gidnumber都是1000,这和vuser:vgroup uid/gid一致,是因为maildrop投递时会从数据库里取uidnumber/gidnumber,而在master.cf里已经定义好了投递时的运行身份(vuser:vgroup),所以这两个字段的内容必须为1000,否则将出现投递错误,例如报0x06等错误。

注意:由于公网上的文档资料是以mail.extmail.org为域名,所以需要将数据库中的所有extmail.org替换成自己本地的域名(test.com),可以用linux下的Vi编辑器打开数据库文件,该文件的位置是/var/www/extsuite/extman/docs。然后依次打开init.sqlextmail.sql将所有的extmail.org替换成test.com。如图例2所示已经替换完成。最后使用update命令将数据库extmail中的所有表数据记录均完成extmail.orgtest.com的替换。

wKioL1Y7DNCRODiuAAVhkFN95cM054.jpg

2.8.3设置虚拟域和虚拟用户的配置文件

# cd /var/www/extsuite/extman/docs

# cp mysql_virtual_alias_maps.cf/etc/postfix/

# cp mysql_virtual_domains_maps.cf/etc/postfix/

# cp mysql_virtual_mailbox_maps.cf/etc/postfix/

# cp mysql_virtual_sender_maps.cf/etc/postfix/


# vi /etc/postfix/main.cf

增加以下内容:

# extmail config here

virtual_alias_maps =mysql:/etc/postfix/mysql_virtual_alias_maps.cf

virtual_mailbox_domains =mysql:/etc/postfix/mysql_virtual_domains_maps.cf

virtual_mailbox_maps =mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf

virtual_transport = maildrop:

 

# service postfix restart

2.8.4测试authlib

# cd /var/www/extsuite/extman/tools

# ./maildirmake.pl/home/domains/extmail.org/postmaster/Maildir

# chown -R vuser:vgroup/home/domains/extmail.org

 

# /usr/sbin/authtest -s login postmaster@(extmail.org-->test.com) extmail

结果如下:

Authentication succeeded.

     Authenticated: postmaster@test.com (uid 1000, gid 1000)

   Home Directory: /home/domains/test.com/postmaster

          Maildir: /home/domains/test.com/postmaster/Maildir/

            Quota: 104857600S

Encrypted Password:$1$phz1mRrj$3ok6BjeaoJYWDBsEPZb5C0

Cleartext Password: extmail

          Options: (none)

这样表明ExtMan的正确安装,数据库也正确导入,courier-authlib能正确连接到mysql数据库

最后访问http://mail.test.com/extmail/,如无意外,将看到webmail的登陆页,不过此时还没有加正式的用户,所以不能登陆,包括postmaster@test.com也不行。必须要登陆到http://mail.test.com/extman/ 里增加一个新帐户才能登陆。

 

ExtMan的默认超级管理员帐户:root@test.com,初始密码:extmail*123*,登陆成功后,建议将密码修改,以确保安全。

2.8.5配置图形化日志

启动mailgraph_ext

# /usr/local/mailgraph_ext/mailgraph-initstart

启动cmdserver(在后台显示系统信息)

# /var/www/extsuite/extman/daemon/cmdserver–daemon

加入开机自启动:

# echo"/usr/local/mailgraph_ext/mailgraph-init start" >>/etc/rc.d/rc.local

# echo"/var/www/extsuite/extman/daemon/cmdserver -v -d" >>/etc/rc.d/rc.local

用方法:等待大约15分钟左右,如果邮件系统有一定的流量,即可登陆到extman里,点“图形日志”即可看到图形化的日志。具体每天,周,月,年的则点击相应的图片进入即可。


添加定时任务:

# crontab –e

wKiom1Y7DYDR_nnYAAEiprv3Uzk817.jpg

2.9 配置Cyrus-SASL

2.9.1安装cyrus-sasl

删除系统的cyrus-sasl

# rpm -e cyrus-sasl –nodeps

安装新的支持authdaemon的软件包

# yum install cyrus-sasl

2.9.2配置main.cf文件

PostfixSMTP认证需要透过Cyrus-SASL,连接到authdaemon获取认证信息。

# vi /etc/postfix/main.cf

增加如下内容:

# smtpd related config

smtpd_recipient_restrictions =

       permit_mynetworks,

        permit_sasl_authenticated,

       reject_non_fqdn_hostname,

       reject_non_fqdn_sender,

       reject_non_fqdn_recipient,

       reject_unauth_destination,

       reject_unauth_pipelining,

       reject_invalid_hostname,

# SMTP sender login matching config

smtpd_sender_restrictions =

       permit_mynetworks,

       reject_sender_login_mismatch,

       reject_authenticated_sender_login_mismatch,

       reject_unauthenticated_sender_login_mismatch

smtpd_sender_login_maps =

       mysql:/etc/postfix/mysql_virtual_sender_maps.cf,

       mysql:/etc/postfix/mysql_virtual_alias_maps.cf

# SMTP AUTH config here

broken_sasl_auth_clients = yes

smtpd_sasl_auth_enable = yes

smtpd_sasl_local_domain = $myhostname

smtpd_sasl_security_options = noanonymous

2.9.3编辑smtpd.conf文件

# vi /usr/lib/sasl2/smtpd.conf

确保其内容为:

pwcheck_method: authdaemond

log_level: 3

mech_list: PLAIN LOGIN

authdaemond_path:/var/spool/authdaemon/socket

重新启动postfix

# service postfix start

2.9.4测试SMTP认证

通过以下命令获得postmaster@test.com的用户名及密码的BASE64编码:

# perl -e 'use MIME::Base64; print encode_base64("postmaster\@test.com")'

内容如下结构:

cG9zdG1hc3RlckBleHRtYWlsLm9yZw==

# perl -e 'use MIME::Base64; printencode_base64("extmail")'

内容如下结构:

ZXh0bWFpbA==

# telnet localhost 25(需要本机安装telnet软件包)

过程如下:

Trying 127.0.0.1...

Connected to localhost.localdomain(127.0.0.1).

Escape character is '^]'.

220 mail.test.com ESMTP Postfix - by test.com

ehlo demo.domain.tld     << 输入内容

250-mail.test.com

250-PIPELINING

250-SIZE 10240000

250-VRFY

250-ETRN

250-AUTH LOGIN PLAIN

250-AUTH=LOGIN PLAIN

250-ENHANCEDSTATUSCODES

250-8BITMIME

250 DSN

auth login     << 输入内容

334 VXNlcm5hbWU6

cG9zdG1hc3RlckBleHRtYWlsLm9yZw==     << 输入内容(通过per命令获取的用户名)

334 UGFzc3dvcmQ6

ZXh0bWFpbA==     << 输入内容(通过per命令获取的用户名密码)

235 2.0.0 Authentication successful

quit    << 输入内容

221 2.0.0 Bye

最后出现235 Authentication Successful 表明认证成功了。

2.10 配置Courier-IMAP

2.10.1安装Courier-imap

默认的courier-authlibcourier-imap都会增加系统自启动设置,因此下一次服务器启动将自动启动相应的authlibPOP3服务

# yum install courier-imap

由于Courier-imapIMAP目录是按UTF-7编码的,ExtMail目前还没有正式支持IMAP目录,因此需要屏蔽IMAP,只提供pop3服务。

# vi /usr/lib/courier-imap/etc/imapd

修改内容如下:

IMAPDSTART=NO

# vi /usr/lib/courier-imap/etc/imapd-ssl

修改内容如下:

IMAPDSSLSTART=NO

然后重新启动courier-imap

# service courier-imap start

2.10.2测试POP3工作是否正常

测试POP3 请按如下步骤输入pop3命令测试其是否正常工作,注意蓝色的信息是我们输入到POP3服务器的(请首先登录extman自行建立test@test.com用户,密码:123qaz!)

# telnet localhost 110

其过程如下:

Trying 127.0.0.1...

Connected to localhost.localdomain(127.0.0.1).

Escape character is '^]'.

+OK Hello there.

user test@test.com     << 输入内容

+OK Password required.

pass 123qaz!     << 输入内容

+OK logged in.

list    << 输入内容

+OK POP3 clients that break here, theyviolate STD53.

.

quit    << 输入内容

+OK Bye-bye.

Connection closed by foreign host.

出现以上内容说明配置正确。

三、注意事项

以上手册内容的结构体系引自http://wiki.extmail.org/extmail_solution_for_centos-5,但由于官网编写较粗略,其中个别细节问题需要注意。

  • 2.9.4测试SMTP认证时会出现错误,通过查看错误信息/var/log/messages,执行#cp -f /usr/lib/sasl2/smtpd.conf /usr/lib64/sasl2/             #/etc/init.d/saslauthd restart完成以上两步操作之后就可以成功通过SMTP测试。

  • 2.10.2测试POP3工作是否正常之前需要提前在mail.test.com/extman后台管理端添加用户,否则会出现错误。