1 Extmail概述
ExtMail Solution 是一个基于优秀开源软件的电子邮件系统解决方案,核心部件包括了Postfix、Amavisd-new、ClamAV、ExtMail、ExtMan、Courier系列软件。是一个功能相对比较齐全的免费电子邮件系统。
而其中Extmail 是一个以perl语言编写,面向大容量/ISP级应用,免费的高性能Webmail软件,主要包括ExtMail、Extman两个部分的程序套件。ExtMail套件用于提供从浏览器中登录、使用邮件系统的Web操作界面,而Extman套件用于提供从浏览器中管理邮件系统的Web操作界面。
2 Extmail工作原理
Extmail的核心部分是postfix,是一种web页面,可以创建账号,可以收发邮件。extman可以账号注册。账号存放在mysql里面。postfix发信件,dovecot收信件。利用outlook收信件(docecot)和发信件(postfix)都要通过mysql查询。发信件(postfix)要提取mysql账号信息要通过courier-authlib。是基于虚拟帐号的邮件系统。
3 Extmail服务器搭建
3.1 安装相关软件包
[[email protected] ~]# yum --disablerepo=\* --enablerepo=c6-media install httpd mysql mysql-server mysql-devel openssl-devel dovecot perl-DBD-MySQL tcl tcl-devel libart_lgpl libart_lgpl-devel libtool-ltdl libtool-ltdl-devel expect
安装开发工具包
[[email protected] ~]# yum --disablerepo=\* --enablerepo=c6-media grouplist 查看
"Development Libraries""Development Tools""Server Platform Development"
3.2 启动httpd mysqld服务
[[email protected] ~]# service httpd start
[[email protected] ~]# service mysqld restart
[[email protected] ~]# chkconfig httpd on
[[email protected] ~]# chkconfig mysqld on 设置开机启动
[[email protected] ~]# netstat -tupln |grep httpd
[[email protected] ~]# netstat -tupln |grep mysqld
[[email protected] ~]# mysqladmin -u root -p password ‘123‘ 为数据库设置密码
3.3 安装Postfix
(1)删除原有postfix 新建用户
[[email protected] ~]# rpm -qa postfix 查看已安装postfix
postfix-2.6.6-2.2.el6_1.i686
[[email protected] ~]# yum --disablerepo=\* --enablerepo=c6-media remove postfix 卸载postfix
[[email protected] ~]# rpm -qa postfix 删除用户和组
[[email protected] ~]# groupdel postfix
[[email protected] ~]# rm -rf /var/spool/postfix 删除用户目录
[[email protected] ~]# groupadd -g 2525 postfix 创建用户组
[[email protected] ~]# useradd -g postfix -u 2525 -s /sbin/nologin -M postfix
[[email protected] ~]# groupdel postdrop
[[email protected] ~]# groupadd -g 2526 postdrop
[[email protected] ~]# useradd -g postdrop -u 2526 -s /bin/false -M postdrop
查看/etc/passwd/
(2)安装postfix
[[email protected] src]# tar -zxvf postfix-2.8.2.tar.gz -C /usr/local/src/
[[email protected] src]# cd postfix-2.8.2/
已有makefile文件,不需要./configure
[[email protected] postfix-2.8.2]# make makefiles ‘CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl -DUSE_TLS ‘ ‘AUXLIBS=-L/usr/lib/mysql -lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2 -lssl -lcrypto‘
错误 :
安装 db4-devel 和gcc
[[email protected] postfix-2.8.2]make && make install
按照以下的提示输入相关的路径([]号中的是缺省值,”]”后的是输入值,省略的表示采用默认值)
install_root: [/] /
tempdir: [/usr/local/src/ postfix-2.6.5] /tmp
config_directory: [/etc/postfix] /etc/postfix
daemon_directory: [/usr/libexec/postfix]
command_directory: [/usr/sbin]
queue_directory: [/var/spool/postfix]
sendmail_path: [/usr/sbin/sendmail]
newaliases_path: [/usr/bin/newaliases]
mailq_path: [/usr/bin/mailq]
mail_owner: [postfix]
setgid_group: [postdrop]
html_directory: [no] /var/www/postfix_html
manpages: [/usr/local/man]
readme_directory: [no]
(4)postfix的启动
[[email protected] postfix-2.8.2]# newaliases 生成别名二进制文件步骤如果忽略,会造成postfix效率低
创建临时目录,把光盘上的postfix rpm软件包拷到临时目录下,这个包里面有postfix的控制脚本
[[email protected] cdrom]# cp /media/cdrom/Packages/postfix-2.6.6-2.2.el6_1.i686.rpm /tmp/abc/
[[email protected] cdrom]# cd /tmp/abc/
[[email protected] abc]# rpm2cpio postfix-2.6.6-2.2.el6_1.i686.rpm |cpio -id 拆解rpm包
[[email protected] init.d]# cp -p postfix /etc/init.d/
[[email protected] init.d]# service postfix start
[[email protected] ~]# tail -f /var/log/maillog 查看日志
warning: not owned by postfix: /var/lib/postfix/./master.lock 文件无所有者
[[email protected] ~]# chown -R postfix /var/lib/postfix/ 修改权限
[[email protected] ~]# chkconfig --add postfix
[[email protected] ~]# chkconfig postfix on 开机自启
(5)postfix配置
[[email protected] ~]# vim /etc/postfix/main.cf
75 myhostname = mail.cj.com
83 mydomain = cj.com
98 myorigin = $myhostname
99 myorigin = $mydomain
113 inet_interfaces = all
161 mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
260 mynetworks = 192.168.30.0/24, 127.0.0.0/8 网络为本机网络
(6)验证
[[email protected] ~]# service postfix restart
错误:
[[email protected] ~]# mail user1
-bash: mail: command not found
[[email protected] ~]# yum install mailx 安装mailx
[[email protected] ~]# mail user1
Subject: 177
qqqqqccccc
. 以点结束
EOT
[[email protected] ~]# tail -f /var/log/maillog 查看邮件日志
也可以
[[email protected] ~]# cd /var/spool/mail/
[[email protected] mail]# vim user1
3.4 postfix开启基于cyrus-sasl的认证功能
(1)查看已安装sasl有关的软件包
[[email protected] mail]# rpm -qa |grep sasl
cyrus-sasl-lib-2.1.23-13.el6_3.1.i686
cyrus-sasl-2.1.23-13.el6_3.1.i686
cyrus-sasl-devel-2.1.23-13.el6_3.1.i686
cyrus-sasl-md5-2.1.23-13.el6_3.1.i686
cyrus-sasl-plain 没有安装
[[email protected] Packages]# ll |grep sasl 查看sasl安装软件包
[[email protected] Packages]# yum install cyrus-sasl-plain-2.1.23-13.el6_3.1.i686.rpm
(2)postfix与sasl结合,编辑Postfix文件
[[email protected] ~]# vim /etc/postfix/main.cf
以下是文本
############################CYRUS-SASL############################
broken_sasl_auth_clients = yes smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,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
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_security_options = noanonymous
smtpd_banner = Welcome to our $myhostname ESMTP,Warning: Version not Available!
(3)验证
[[email protected] ~]# service postfix restart
[[email protected] ~]# telnet 127.0.0.1 25
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is ‘^]‘.
220 Welcome to our mail.cj.com ESMTP,Warning: Version not Available!
(4)sasl配置
[[email protected] ~]# mkdir /usr/local/lib/sasl2
[[email protected] ~]# vim /usr/local/sasl2smtpd.conf
[[email protected] ~]# service saslauthd start
[[email protected] ~]# chkconfig --add saslauthd
[[email protected] ~]# chkconfig saslauthd on
3.5安装Courier authentication library
(1)解压安装
[[email protected] ~]# tar -jxvf courier-authlib-0.63.0.tar.bz2 -C /usr/local/src/
[[email protected] ~]# cd /usr/local/src/courier-authlib-0.63.0/
[[email protected] courier-authlib-0.63.0]# 编译
./configure \
--prefix=/usr/local/courier-authlib \
--sysconfdir=/etc \
--with-authmysql \
--with-mysql-libs=/usr/lib/mysql \
--with-mysql-includes=/usr/include/mysql \
--with-redhat \
--with-authmysqlrc=/etc/authmysqlrc \
--with-authdaemonrc=/etc/authdaemonrc
[[email protected] courier-authlib-0.63.0]# make && make install 安装
(2)配置SMTP
vim /usr/local/lib/sasl2/smtpd.conf
(3)修改配置
[[email protected] ~]# chmod 755 /usr/local/courier-authlib/var/spool/authdaemon/
[[email protected] ~]# cp /etc/authdaemonrc.dist /etc/authdaemonrc
[[email protected] ~]# cp /etc/authmysqlrc.dist /etc/authmysqlrc
[[email protected] ~]# vim /etc/authdaemonrc
vim /etc/authdaemonrc
authmodulelist="authmysql" 修改
authmodulelistorig="authmysql"
daemons=10
[[email protected] ~]# vim /etc/authmysqlrc
MYSQL_SERVER localhost
MYSQL_PORT 3306 (指定你的mysql监听的端口,这里使用默认的3306)
MYSQL_USERNAME extmail (这时为后文要用的数据库的所有者的用户名)
MYSQL_PASSWORD extmail (密码)
MYSQL_SOCKET /var/lib/mysql/mysql.sock
MYSQL_DATABASE extmail
MYSQL_USER_TABLE mailbox
MYSQL_CRYPT_PWFIELD password
MYSQL_UID_FIELD ‘2525‘
MYSQL_GID_FIELD ‘2525‘
MYSQL_LOGIN_FIELD username
MYSQL_HOME_FIELD concat(‘/var/mailbox/‘,homedir)
MYSQL_NAME_FIELD name
MYSQL_MAILDIR_FIELD concat(‘/var/mailbox/‘,maildir)
产生启动控制脚本
[[email protected] courier-authlib-0.63.0]# cp courier-authlib.sysvinit /etc/init.d/courier-authlib
[[email protected] courier-authlib-0.63.0]# chmod 755 /etc/init.d/courier-authlib 增加可执行权限
[[email protected] courier-authlib-0.63.0]# chkconfig --add courier-authlib
[[email protected] courier-authlib-0.63.0]# chkconfig --level 2345 courier-authlib on
[[email protected] courier-authlib-0.63.0]# echo "/usr/local/courier-authlib/lib/courier-authlib" >> /etc/ld.so.conf.d/courier-authlib.conf
[[email protected] courier-authlib-0.63.0]# ldconfig -v 启动courier-authlib服务
[[email protected] courier-authlib-0.63.0]# mkdir -pv /var/mailbox 新建虚拟用户邮箱所在的目录,并将其权限赋予postfix用户
[[email protected] courier-authlib-0.63.0]# chown -R postfix /var/mailbox
3.5 postfix支持虚拟域和虚拟用户
(1)编辑/etc/postfix/main.cf
##################Virtual Mailbox Settings#################
virtual_mailbox_base = /var/mailbox
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_alias_domains =
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_uid_maps = static:2525
virtual_gid_maps = static:2525
virtual_transport = virtual
maildrop_destination_recipient_limit = 1
maildrop_destination_concurrency_limit = 1
####################QUOTA Settings######################
message_size_limit = 14336000
virtual_mailbox_limit = 20971520
virtual_create_maildirsize = yes
virtual_mailbox_extended = yes
virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf
virtual_mailbox_limit_override = yes
virtual_maildir_limit_message = Sorry, the user‘s maildir has overdrawn his diskspace quota, please Tidy your mailbox and try again later.
virtual_overquota_bounce = yes
(2)使用extman源码目录下docs目录中的extmail.sql和init.sql建立数据库:
[[email protected] ~]# cd extman-1.1/docs
[[email protected] docs]# cp mysql_virtual_* /etc/postfix/
//导入数据库
[[email protected] docs]# mysql -u root -p <extmail.sql
[[email protected] docs]# mysql -u root -p <init.sql
(3)授予用户extmail访问extmail数据库的权限
[[email protected] docs]# mysql -u root -p
mysql> GRANT all privileges on extmail.* TO [email protected] IDENTIFIED BY ‘extmail‘;
mysql> GRANT all privileges on extmail.* TO [email protected] IDENTIFIED BY ‘extmail‘;
mysql> FLUSH PRIVILEGES;
[[email protected] docs]# service postfix restart
3.6 配置dovecot
(1)编辑dovecot配置文件
[[email protected] ~]# cd /etc/dovecot/conf.d
vim 10-mail.conf
24 mail_location = maildir:/var/mailbox/%d/%n/Maildir
[[email protected] conf.d]# vim /etc/postfix/main.cf
415 home_mailbox = Maildir/
[[email protected] conf.d]# mv auth-sql.conf.ext auth-sql.conf
[[email protected] conf.d]# vim auth-sql.conf
[[email protected] dovecot]# vim /etc/dovecot-mysql.conf
driver = mysql
connect = host=localhost dbname=extmail user=extmail password=extmail (如mysql源码安装,host=/tmp/mysql.sock)
default_pass_scheme = CRYPT
password_query = SELECT username AS user,password AS password FROM mailbox WHERE username = ‘%u‘
user_query = SELECT maildir, uidnumber AS uid, gidnumber AS gid FROM mailbox WHERE username = ‘%u‘
[[email protected] dovecot]# service dovecot start
Starting Dovecot Imap: [ OK ]
[[email protected] dovecot]# chkconfig dovecot on
3.7 安装Extmail-1.2
(1)安装
[[email protected] ~]# tar -zxvf extmail-1.2.tar.gz
[[email protected] ~]# mkdir -pv /var/www/extsuite
mkdir: created directory `/var/www/extsuite‘
[[email protected] ~]# mv extmail-1.2 /var/www/extsuite/extmail
[[email protected] ~]# cd /var/www/extsuite/extmail/
[[email protected] extmail]# cp webmail.cf.default webmail.cf
(2)修改主配置文件
#vi /var/www/extsuite/extmail/webmail.cf
部分修改选项的说明:
SYS_MESSAGE_SIZE_LIMIT = 5242880
用户可以发送的最大邮件
SYS_USER_LANG = en_US
语言选项,可改作:
SYS_USER_LANG = zh_CN
SYS_MAILDIR_BASE = /home/domains
此处即为您在前文所设置的用户邮件的存放目录,可改作:
SYS_MAILDIR_BASE = /var/mailbox
SYS_MYSQL_USER = db_user
SYS_MYSQL_PASS = db_pass
以上两句句用来设置连接数据库服务器所使用用户名、密码和邮件服务器用到的数据库,这里修改为:
SYS_MYSQL_USER = extmail
SYS_MYSQL_PASS = extmail
SYS_MYSQL_HOST = localhost
指明数据库服务器主机名,这里默认即可
SYS_MYSQL_TABLE = mailbox
SYS_MYSQL_ATTR_USERNAME = username
SYS_MYSQL_ATTR_DOMAIN = domain
SYS_MYSQL_ATTR_PASSWD = password
以上用来指定验正用户登录里所用到的表,以及用户名、域名和用户密码分别对应的表中列的名称;这里默认即可
SYS_AUTHLIB_SOCKET = /var/spool/authdaemon/socket
此句用来指明authdaemo socket文件的位置,这里修改为:
SYS_AUTHLIB_SOCKET = /usr/local/courier-authlib/var/spool/authdaemon/socket
(3)apache相关配置
[[email protected] extmail]# vim /etc/httpd/conf/httpd.conf
1010 <VirtualHost *:80>
1011 ServerName mail.test.com
1012 DocumentRoot /var/www/extsuite/extmail/html/
1013 ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi
1014 Alias /extmail /var/www/extsuite/extmail/html
1015 SuexecUserGroup postfix postfix
1016 </VirtualHost>
[[email protected] extmail]# service httpd restart 重启httpd服务
[[email protected] extmail]#yum install perl-CGI*
(4)依赖关系的解决
extmail将会用到perl的Unix::syslogd功能,您可以去http://search.cpan.org搜索下载原码包进行安装。
[[email protected] ~]# tar -zxvf Unix-Syslog-0.100.tar.gz -C /usr/local/src/
cd /usr/local/src/Unix-Syslog-0.100/
perl Makefile.PL
make && make install
(5)启动apache服务
[[email protected] ~]# service httpd start
[[email protected] ~]# chkconfig httpd on
3.8安装Extman-1.1
[[email protected] ~]# mv extman-1.1 /var/www/extsuite/extman
[[email protected] ~]# cd /var/www/extsuite/extman
[[email protected] extman]# mv webman.cf.default webman.cf
[[email protected] extman]# vim webman.cf
[[email protected] extman]# chown -R postfix.postfix /var/www/extsuite/extman/cgi/
[[email protected] extman]# vim /etc/httpd/conf/httpd.conf
加上这两行
1015 ScriptAlias /extman/cgi /var/www/extsuite/extman/cgi
1016 Alias /extman /var/www/extsuite/extman/html
4 测试
(1)访问12.168.30.4
(2)进入后台管理
用户名[email protected]
密码extmail*123*
注册域
(3)注册邮箱[email protected] 并发送邮件测试
至此 extmail搭建完毕
centos下Extmail的搭建,布布扣,bubuko.com