Extmail

一、系统环境

(1)编译环境

  [root@web_mail]# yum install gcc gcc-c++

(2)依赖软件

  [root@web_mail]# yum install openssl openssl-devel cyrus-sasl libtool-ltdl libtool-ltdl-devel db4 db4-devel expect expect-devel pcre pcre-devel

(3)LAMP环境

  [root@web_mail]# yum install httpd httpd-devel mysql mysql-server mysql-devel php php-mysql

(4)设置mysql,apache开机启动

  [root@web_mail ~]# chkconfig mysqld on

  [root@web_mail ~]# chkconfig httpd on

二、安装POSTFIX

(1)安装

  [root@web_mail ~]# yum install postfix

(2)配置

  [root@web_mail ~]# cd /etc/postfix/

  [root@web_mail postfix]# postconf -n > /etc/postfix/main2.cf

  [root@web_mail postfix]# mv main.cf main.cf.old

  [root@web_mail postfix]# mv main2.cf main.cf

  [root@web_mail postfix]# vi main.cf

#inet_interfaces = localhost 注释掉下面这行,否则25端口只能本地连接
#添加以下基本配置
mynetworks = 127.0.0.1  
myhostname = mail.xxx.com 主机设置
mydestination = $myhostname, localhost.$mydomain, localhost
mail_name = Postfix - by playdod.com
smtpd_banner = $myhostname ESMTP $mail_name
smtpd_error_sleep_time = 0s
message_size_limit = 10485760 邮件大小10M
mailbox_size_limit = 2097152000 邮箱大小2G
show_user_unknown_table_name = no
bounce_queue_lifetime = 1d
maximal_queue_lifetime = 1d

(3)启动

  [root@web_mail postfix]# service postfix start

  [root@web_mail postfix]# chkconfig postfix on

  [root@web_mail postfix]# ps aux|grep postfix

  [root@web_mail postfix]# netstat -tlnp|grep 25

(4)检查

  [root@web_mail postfix]# postfix check

  [root@web_mail postfix]# postconf –a   出现cyrus表示可以支持cyrus认证用户

  [root@web_mail postfix]# postconf -m   出现mysql表示可以支持mysql存储账号

三、安装Courier-Authlib

(1)安装

  [root@web_mail postfix]# groupadd vmail -g 1002

  [root@web_mail postfix]# useradd vmail -u 1002 -g 1002 -d /home/domains

  [root@web_mail postfix]# cd /usr/local/src

  [root@web_mail src]#wget http://cznic.dl.sourceforge.net/project/courier/authlib/0.66.1/
courier-authlib-0.66.1.tar.bz2

  [root@web_mail src]# tar -jxf courier-authlib-0.66.1.tar.bz2

  [root@web_mail src]# cd courier-authlib-0.66.1

  [root@web_mail courier-authlib-0.66.1]# ./configure –with-mysql-libs –with-mysql-includes   –with-authmysql –with-authmysql=yes –with-mailuser=vmail –with-mailgroup=vmail

  [root@web_mail courier-authlib-0.66.1]# make && make install

  [root@web_mail courier-authlib-0.66.1]# make install-configure

(2)修改配置文件

  [root@web_mail courier-authlib-0.66.1]# cd /usr/local/etc/authlib

  [root@web_mail authlib]# vi 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 1002
MYSQL_GID_FIELD 1002
MYSQL_LOGIN_FIELD username
MYSQL_HOME_FIELD homedir
MYSQL_NAME_FIELD name
MYSQL_MAILDIR_FIELD maildir
MYSQL_QUOTA_FIELD quota
MYSQL_SELECT_CLAUSE SELECT username,password,"",uidnumber,gidnumber,\
CONCAT('/home/domains/',homedir), \
CONCAT('/home/domains/',maildir), \
quota, \
name \
FROM mailbox \
WHERE username = '$(local_part)@$(domain)'

  [root@web_mail authlib]# vi authdaemonrc

authmodulelist="authmysql"
authmodulelistorig="authmysql"

  [root@web_mail authlib]# ln -s /usr/local/etc/authlib /etc/authlib

(3)启动

  [root@web_mail authlib]# /usr/local/sbin/authdaemond start

  [root@web_mail authlib]# ps aux|grep authdaemond

  [root@web_mail authlib]# echo “/usr/local/sbin/authdaemond start” >> /etc/rc.d/rc.local

四、安装Maildrop

(1) 安装Courier-Unicode

  [root@web_mail authlib]# cd /usr/local/src

  [root@web_mail src]# tar -jxf courier-unicode-1.1.tar.bz2

  [root@web_mail src]# cd courier-unicode-1.1

  [root@web_mail courier-unicode-1.1]# ./configure

  [root@web_mail courier-unicode-1.1]# make && make install

(2) 安装Maildrop

  [root@web_mail courier-unicode-1.1]# cd /usr/local/src

  [root@web_mail src]# tar -jxf maildrop-2.7.2.tar.bz2

  [root@web_mail src]# cd maildrop-2.7.2

  [root@web_mail maildrop-2.7.2]# ./configure
–enable-maildirquota –enable-maildrop-uid=1002 –enable-maildrop-gid=1002 –with-trashquota

  [root@web_mail maildrop-2.7.2]# make && make install

(3) 配置

  [root@web_mail maildrop-2.7.2]# vi /etc/postfix/master.cf

maildrop unix - n n - - pipe
flags=DRhu user=vmail argv=/usr/local/bin/maildrop -w 90 -d ${user}@${nexthop} ${recipient} ${user} ${extension} {nexthop}

[root@web_mail maildrop-2.7.2]# vi /etc/postfix/main.cf

maildrop_destination_recipient_limit = 1

五、安装Webmail前台

(1)安装

  [root@web_mail src]# tar -zxvf extmail-1.2.tar.gz

  [root@web_mail src]# tar -zxvf extman-1.1.tar.gz

  [root@web_mail src]# mkdir /var/www/extsuite

  [root@web_mail src]# mv extman-1.1 /var/www/extsuite/extman

  [root@web_mail src]# mv extmail-1.2 /var/www/extsuite/extmail

(2)配置extmail

  [root@web_mail src]# cd /var/www/extsuite

  [root@web_mail extsuite]# cp extmail/webmail.cf.default extmail/webmail.cf

  [root@web_mail extsuite]# vi extmail/webmail.cf

SYS_MYSQL_USER = extmail
SYS_MYSQL_PASS = extmail

(3)配置extman

  [root@web_mail extsuite]# mkdir /var/www/extsuite/extman/session

  [root@web_mail extsuite]# cp extman/webman.cf.default extman/webman.cf

  [root@web_mail extsuite]# vi extman/webman.cf

SYS_SESS_DIR = /var/www/extsuite/extman/session/
SYS_DEFAULT_UID = 1002
SYS_DEFAULT_GID = 1002

(4)初始化数据库

[1] 给数据库root用户设置密码

  [root@web_mail extsuite]# service mysqld restart

  [root@web_mail extsuite]# mysql –uroot

  mysql> set password for root@localhost=password(‘123456’);

  mysql> quit

[2] 导入extmail数据库

  [root@web_mail extsuite]# mysql -uroot -p123456 < extman/docs/extmail.sql

[3] 修改参数后导入数据

  [root@web_mail extsuite]#sed –i ‘s/extmail.org/playdod.com/g’ extman/docs/init.sql

  [root@web_mail extsuite]# sed -i ‘s/1000/1002/g’ extman/docs/init.sql

  [root@web_mail extsuite]# mysql -uroot -p123456 </var/www/extsuite/extman/docs/init.sql

[4] 查看数据库

  [root@web_mail extsuite]# mysql -uroot -p123456

  mysql> use extmail;

  > show tables;

  mysql> select username,uidnumber,gidnumber from mailbox;

(5)配置postfix

  [root@webmail extsuite]# cp extman/docs/mysql*.cf /etc/postfix/

  [root@web_mail extsuite]# vi /etc/postfix/main.cf

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
virtual_uid_maps = static:1002
virtual_gid_maps = static:1002

(6)设置权限和属主

  [root@web_mail extsuite]# chown root.root -R extmail extman

  [root@web_mail extsuite]# chown -R vmail:vmail extmail/cgi/ extman/cgi/ extman/session

(7)配置Apache虚拟主机

  [root@web_mail extsuite]# vi /etc/httpd/conf.d/extmail.conf

# VirtualHost for ExtMail Solution
NameVirtualHost *:80
<VirtualHost *:80>
ServerName mail.xx.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 vmail vmail
</VirtualHost>

(8)重启服务

  [root@web_mail extsuite]# service postfix restart

  [root@web_mail extsuite]# service httpd restart

(9)建立Maildir

[1] 手动建立Maildir

用于存放用户邮件的目录;在WEB上创建其他域名邮箱,会在此自动建立相应域
名目录。

  [root@web_mail extsuite]# cd extman/tools

  [root@web_mail tools]#
./maildirmake.pl /home/domains/playdod.com/postmaster/Maildir

  [root@web_mail tools]# chown -R vmail:vmail /home/domains

[2]测试authlib认证登录账号

  [root@web_mail tools]# /usr/local/sbin/authtest -s login postmaster@playdod.com extmail

(10)安装其他依赖包

[1]安装绘图工具

  [root@web_mail tools]# yum install -y rrdtool rrdtool-perl

[2]安装依赖perl模块

  [root@web_mail tools]# yum install -y cpan perl

  [root@web_mail tools]# yum install -y perl-YAML perl-Test-Exception
perl-Crypt-PasswdMD5 perl-GD perl-CGI perl-Time-HiRes

  [root@web_mail tools]# perl -MCPAN -e ‘install Time::HiRes::Value’

  [root@web_mail tools]# perl -MCPAN -e ‘install File::Tail’

  [root@web_mail tools]# perl -MCPAN -e ‘install Unix::Syslog’

  [root@web_mail tools]# perl -MCPAN -e ‘install DB_File’

  [root@web_mail tools]# perl -MCPAN -e ‘install Encode::HanExtra’

[3]启动进程

  [root@web_mail tools]# cd /var/www/extsuite/extman

  [root@web_mail extman]# cp -R addon/mailgraph_ext/ /usr/local/

  [root@web_mail extman]# /usr/local/mailgraph_ext/mailgraph-init start

  

  [root@web_mail extman]# ps aux|grep mailgraph_ext

  

  [root@web_mail extman]# /var/www/extsuite/extman/daemon/cmdserver -v -d

  [root@web_mail extman]# ps aux|grep cmdserver

  

  [root@web_mail extman]#echo “/usr/local/mailgraph_ext/mailgraph-init
start” >> /etc/rc.d/rc.local

[root@web_mail extman]# echo “/var/www/extsuite/extman/daemon/cmdserver
-v -d” >> /etc/rc.d/rc.local

[4]定时任务

  [root@web_mail extman]# crontab -e

0 4 * * * /var/www/extsuite/extman/tools/expireusers.pl -all postmaster@playdod.com
30 4 * * * /var/www/extsuite/extman/tools/reportusage.pl -all /home/domains postmaster@playdod.com

  [root@web_mail extman]# service crond restart

  [root@web_mail extsuite]# vi /var/www/extsuite/extman/webman.cf   取消管理后台登陆验证码

SYS_CAPTCHA_ON = 0

(11)测试web访问

[1]访问邮箱

<1>帐号:postmaster

<2>密码:extmail

<3>域名:xxx.com

[2]访问邮箱后台

<1>帐号: root@xx.com

<2>密码: xxxx*

(12)检查Maildrop

[1]查看版本信息

  [root@web_mail extsuite]# maildrop –v

  

[2]测试maildrop连接

  [root@web_mail extsuite]# echo “test” | maildrop -V 10 -d postmaster@playdod.com

  

六、安装Cyrus-SASL使Postfix支持SMTP认证

(1)系统已默认安装Cyrus-SASL

  [root@mail ~]# rpm -aq|grep cyrus-sasl

  

(2)配置cyrus-sasl

vi /etc/sasl2/smtpd.conf

  

  [root@web_mail ~]# chmod 755 /usr/local/var/spool/authdaemon

(3)配置postfix

  [root@web_mail ~]# vi /etc/postfix/main.cf

  

  

  

  

  [root@web_mail ~]# service postfix restart

(4)测试SMTP认证

  [root@web_mail ~]# perl -e ‘use MIME::Base64; print encode_base64

(“postmaster\@playdod.com”)’

  [root@web_mail ~]# perl -e ‘use MIME::Base64; print encode_base64(“extmail”)’

  [root@web_mail ~]# yum install -y telnet

  [root@web_mail ~]# telnet localhost 25

Connected to localhost.
Escape character is '^]'.
220 mail.playdod.com ESMTP Postfix - by playdod.com
ehlo localhost
250-mail.playdod.com
250-PIPELINING
250-SIZE 10485760
250-VRFY
250-ETRN
250-STARTTLS
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
auth login
334 VXNlcm5hbWU6
cG9zdG1hc3RlckBwbGF5ZG9kLmNvbQ==
334 UGFzc3dvcmQ6
YWJjZC4xMjM0
235 2.7.0 Authentication successful
quit
221 2.0.0 Bye
Connection closed by foreign host.

七、实现POP3、IMAP基本功能

(1)安装Courier-IMAP

  [root@web_mail ~]# cd /usr/local/src

  [root@web_mail ~]#=wget http://ncu.dl.sourceforge.net/project/courier/imap/
4.15.1/courier-imap-4.15.1.tar.bz2

  [root@web_mail src]# tar -jxf courier-imap-4.15.1.tar.bz2

  [root@web_mail src]# cd courier-imap-4.15.1

  [root@web_mail courier-imap-4.15.1]# ./configure –enable-workarounds-for-imap-client-bugs –with-authchangepwdir –enable-unicode –with-trashquota –disable-root-check

  [root@web_mail courier-imap-4.15.1]# make && make install

  [root@web_mail courier-imap-4.15.1]# make install-configure

(2)启动程序

  [root@web_mail courier-imap-4.15.1]# cd /usr/lib/courier-imap/

  [root@web_mail courier-imap]# /usr/lib/courier-imap/libexec/imapd.rc start

  [root@web_mail courier-imap]# echo “/usr/lib/courier-imap/libexec/imapd.rc
start” >> /etc/rc.local

  [root@web_mail courier-imap]# ps aux|grep imapd

  

  [root@web_mail courier-imap]# netstat -tnlp|grep 143

  

  [root@web_mail courier-imap]# /usr/lib/courier-imap/libexec/pop3d.rc start

  [root@web_mail courier-imap]# echo “/usr/lib/courier-imap/libexec/pop3d.rc
start” >> /etc/rc.local

  [root@web_mail courier-imap]# ps aux|grep pop3d

  

  [root@web_mail courier-imap]# netstat -tnlp|grep 110

  

(3)设置imapd、pop3为启用状态

  [root@web_mail courier-imap]# sed -i ‘s/IMAPDSTART=NO/IMAPDSTART=YES/g’ etc/imapd

  [root@web_mail courier-imap]# sed -i ‘s/POP3DSTART=NO/POP3DSTART=YES/g’ etc/pop3d

(4)测试端口连接

  [root@web_mail courier-imap]# telnet localhost 110

Connected to localhost.
Escape character is '^]'.
+OK Hello there.
user postmaster@playdod.com
+OK Password required.
pass abcd.1234
+OK logged in.
list
+OK POP3 clients that break here, they violate STD53
1 665
2 665
3 871
4 3245
5 695
6 3297
quit
+OK Bye-bye.
Connection closed by foreign host

  [root@web_mail courier-imap]# telnet localhost 143

Connected to localhost.
Escape character is '^]'.
* OK [CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA IDLE ACL ACL2=UNION STARTTLS] Courier-IMAP ready. Copyright 1998-2011 Double Precision, Inc. See COPYING for distribution information.
tag login postmaster@playdod.com abcd.1234
tag OK LOGIN Ok.
tag logout
* BYE Courier-IMAP server shutting down
tag OK LOGOUT completed
Connection closed by foreign host.

八、Webmail支持FCGI

(1)装apache的mod_fastcgi模块

  [root@web_mail ~]# yum install -y httpd-devel

  [root@web_mail ~]# cd /usr/local/src

  [root@web_mail src]# wget http://www.fastcgi.com/dist/mod_fastcgi-2.4.6.tar.gz

  [root@web_mail src]# tar zxvf mod_fastcgi-2.4.6.tar.gz

  [root@web_mail src]# cd mod_fastcgi-2.4.6

  [root@web_mail mod_fastcgi-2.4.6]# cp Makefile.AP2 Makefile

  [root@web_mail mod_fastcgi-2.4.6]# find / -name “build” -type d

  [root@web_mail mod_fastcgi-2.4.6]# make top_dir=/usr/lib64/httpd/ install

(2)查看模块是否生成

  [root@web_mail mod_fastcgi-2.4.6]# ls /etc/httpd/modules/mod_fastcgi.so

(3)安装Extmail需要的perl-FCGI模块

  [root@web_mail mod_fastcgi-2.4.6]# yum install perl-FCGI

  [root@web_mail mod_fastcgi-2.4.6]# vi /etc/httpd/conf.d/extmail.conf

(4)配置虚拟主机文件

  /Users/yx/blog/source/F6F44294-9C5F-40E1-B9C6-FB25DA663BB4.png

(5)修改启动脚本,并启动

  [root@web_mail mod_fastcgi-2.4.6]# vi /var/www/extsuite/extmail/dispatch-init
SU_UID=vmail

SU_GID=vmail

  [root@web_mail mod_fastcgi-2.4.6]# /var/www/extsuite/extmail/dispatch-init start

  [root@web_mail mod_fastcgi-2.4.6]# echo “/var/www/extsuite/extmail
/dispatch-init start” >> /etc/rc.d/rc.local

  [root@web_mail mod_fastcgi-2.4.6]# service httpd restart

  [root@web_mail mod_fastcgi-2.4.6]# ps aux|grep dispatch.fcgi

  

  [root@web_mail mod_fastcgi-2.4.6]# netstat -tnlp|grep 8888