CentOS6下搭建Extmail邮箱服务

服务组件:

Web 服务器 Apache 2.2.x  
数据库/目录服务 MySQL 5.6.X  
邮件传输代理(MTA) postfix-2.6.2  
邮件投递代理(MDA) maildrop 2.0.x 支持过滤和强大功能
Web帐户管理后台 ExtMan 1.0 支持无限域名、无限用户
WebMail 系统 ExtMail 1.1.0 支持多语言、全部模板化,功能基本齐全
其他数据认证库 Courier Authlb 0.62 负责courier-imap,maildrop的认证
SMTP认证库 Cyrus SASL 2.1.x 标准的SASL实现库,可以支持Courier authlib

本文涉及到的安装包有:

[root@mail extmail_install]# pwd

/root/extmail_install

[root@mail extmail_install]# ll

courier-authlib-0.69.0.tar.bz2
courier-unicode-2.1.tar.bz2
extmail-1.2.tar.gz
extman-1.1.tar.gz
Percona-Server-56-debuginfo-5.6.25-rel73.1.el6.x86_64.rpm
Percona-Server-client-56-5.6.25-rel73.1.el6.x86_64.rpm
Percona-Server-devel-56-5.6.25-rel73.1.el6.x86_64.rpm
Percona-Server-server-56-5.6.25-rel73.1.el6.x86_64.rpm
Percona-Server-shared-56-5.6.25-rel73.1.el6.x86_64.rpm
Percona-Server-test-56-5.6.25-rel73.1.el6.x86_64.rpm
Percona-Server-tokudb-56-5.6.25-rel73.1.el6.x86_64.rpm
postfix      #postfix服务脚本
postfix-3.4-20181202.tar.gz
Unix-Syslog-1.1.tar.gz

 

一、安装依赖包

在线安装

我使用的是CentOS6.9 的最小化安装,所以有些工具没有。

yum install httpd  openssl-devel dovecot dovecot-mysql perl-DBD-MySQL perl-CGI tcl tcl-devel libart_lgpl libart_lgpl-devel libtool-ltdl libtool-ltdl-devel expect  db4-devel -y
yum groupinstall "Development tools"  "Development Libraries" -y
yum install telnet htop man mail -y

二、数据库组件

如果系统已经有mysql则跳过。

2.1 安装数据库mysql

方式一:离线安装  Percona mysql 5.6 ,优点:速度快

rpm -ivh Percona-Server-shared-56-5.6.25-rel73.1.el6.x86_64.rpm
rpm -ivh Percona-Server-devel-56-5.6.25-rel73.1.el6.x86_64.rpm
rpm -ivh Percona-Server-client-56-5.6.25-rel73.1.el6.x86_64.rpm
rpm -ivh Percona-Server-server-56-5.6.25-rel73.1.el6.x86_64.rpm

方式二:在线安装

yum install http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm
yum install Percona-Server-server-56 

注意:Percona Mysql 在安装 Percona-Server-server-56-*之后,会自动使用默认配置初始化库,相当于执行mysql_install_db。

2.2 数据库相关配置:

关闭系统SELINUX

sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux 
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
setenforce 0

配置my.cnf

cp -rf  /etc/my.cnf /etc/my.cnf.bak

echo '[mysqld]
datadir = /opt/data/mysql
tmpdir = /opt/data/tmp
socket= /opt/data/mysql/mysql.sock

# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 
max_allowed_packet=32M
lower_case_table_names=1
max_connections=5000
max_connect_errors = 5000
sql-mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
wait_timeout=120000
interactive_timeout=60000
connect_timeout = 60000

innodb_file_per_table=1
innodb_read_io_threads = 16
innodb_write_io_threads = 16
#thread_concurrency=96
sort_buffer_size = 10M
join_buffer_size = 10M
query_cache_size = 32M
query_cache_limit = 10M
tmp_table_size = 1024M
max_heap_table_size = 256M
binlog_cache_size = 10M
key_buffer_size = 769M  
read_buffer_size = 1M 
myisam_sort_buffer_size = 128M
thread_cache_size = 16

innodb_buffer_pool_size = 5480M 
innodb_log_buffer_size = 412M
innodb_log_file_size = 1024M

server-id=2
#log-bin=mysql-bin
#binlog_format=mixed
#expire_logs_days=1

#binlog_ignore_db = information_schema
#binlog_ignore_db = performance_schema
#binlog_ignore_db = mysql
#binlog_ignore_db = activemq
#binlog_ignore_db = datacenter
#
#binlog_do_db = gms

#replicate_ignore_db = mysql
#replicate_ignore_db = information_schema
#replicate_ignore_db = performance_schema
#replicate_ignore_db = activemq
#replicate_ignore_db = gms
#
#replicate_do_db = datacenter
#
#sync_binlog = 500
innodb_flush_log_at_trx_commit = 2
innodb_flush_method=O_DIRECT
#innodb_io_capacity=200
innodb_stats_on_metadata=OFF
innodb_adaptive_flushing=ON
#innodb_locks_unsafe_for_binlog = 1
#log_slow_queries = /opt/data/mysql/slow_queries.log
slow-query-log = 1
long_query_time = 10
slow-query-log-file = /opt/data/mysql/slow_queries.log
#log-queries-not-using-indexes = 1

[mysql]
default-character-set=utf8
socket=/opt/data/mysql/mysql.sock

[client]
default-character-set=utf8
socket=/opt/data/mysql/mysql.sock
' > /etc/my.cnf

创建mysql数据目录

这里我做了修改,默认路径是/var/lib/mysql/.

#创建目录
mkdir -p /opt/data/mysql /opt/data/log /opt/data/tmp
chown -R mysql.mysql /opt/data

使用新配置文件my.cnf重新初始化数据库

mysql_install_db --user=mysql

打开服务并启动mysql

chkconfig mysql on
service mysql start

修改root密码

mysqladmin password TestPass123

 

二、postfix组件

1.1 安装postfix

卸载系统自带postfix

rpm -qa postfix
rpm -e postfix --nodeps

查看现有postfix用户信息

# id postfix

uid=89(postfix) gid=89(postfix) groups=89(postfix),12(mail)

删除原有的postfix账户

userdel postfix
groupdel postfix
grep postfix /etc/passwd
rm -rf /var/spool/postfix

新建postfix账户

groupadd -g 1000 postfix
useradd -g postfix -u 1000 -s /sbin/nologin -M postfix
groupdel postdrop
groupadd -g 1001 postdrop
useradd -g postdrop -u 1001 -s /sbin/nologin -M postdrop

可以查看新建账户信息

# grep post /etc/passwd

postfix:x:1000:1000::/home/postfix:/sbin/nologin
postdrop:x:1001:1001::/home/postdrop:/sbin/nologin

 

源码安装postfix

#版本:postfix-3.4-20180422,其他版本可到ftp://ftp.cuhk.edu.hk/pub/packages/mail-server/postfix/experimental/下载。

wget ftp://ftp.cuhk.edu.hk/pub/packages/mail-server/postfix/experimental/postfix-3.4-20181202.tar.gz

本教程涉及到的包比较多,因此都提前下载好了,放在一个目录下。

tar zxf postfix-3.4-20181202.tar.gz
cd postfix-3.4-20181202
#已有makefile文件,不需要./configure
make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl -DUSE_TLS ' 'AUXLIBS=-L/usr/lib64/mysql -lmysqlclient -lz -lm -lrt -L/usr/lib64/sasl2 -lsasl2 -lssl -lcrypto'
make && make install && echo ok

按照以下提示输入相关路径,省略表示采用默认值

install_root: [/] /
tempdir: [/root/postfix-3.2-20160327] /tmp    #修改了
config_directory: [/etc/postfix]
command_directory: [/usr/sbin]
daemon_directory: [/usr/libexec/postfix]
data_directory: [/var/lib/postfix]
html_directory: [no] /var/www/postfix_html   #修改了
mail_owner: [postfix]
mailq_path: [/usr/bin/mailq]
manpage_directory: [/usr/local/man]
newaliases_path: [/usr/bin/newaliases]
queue_directory: [/var/spool/postfix]
readme_directory: [no]
sendmail_path: [/usr/sbin/sendmail]
setgid_group: [postdrop]
shlib_directory: [no]
meta_directory: [/etc/postfix]

 

添加postfix服务

从3.4版本的postfix源码包里面没有启动脚本了,需要从别处下载,本文附录有服务脚本。

如果系统里没有安装postfix的rpm包,则可以这样下载rpm包:

yum install --downloadonly --downloaddir=./  postfix-2.6.6 -y

解压rpm包

rpm2cpio postfix-2.6.6-*.rpm | cpio -idmv

复制文件到系统目录

cp -rf etc/rc.d/init.d/postfix /etc/rc.d/init.d/

chmod +x /etc/rc.d/init.d/postfix

本文假设已经下载好了postfix启动脚本在安装包同目录下

cp postfix /etc/rc.d/init.d/
chmod +x /etc/rc.d/init.d/postfix
chown -R postfix /var/lib/postfix
service postfix start
chkconfig --add postfix
chkconfig postfix on

 

修改postfix主配置文件mail.cf

添加配置到/etc/postfix/main.cf文件末尾

echo '
#manual modify
myhostname = mail.mydomain.com
mydomain = mydomain.com
#邮件地址伪装mail.mydomain.com为mydomain.com
myorigin = $mydomain
inet_interfaces = all
#所有目标邮件为以上的就是本机,不用中继了
mynetworks = 192.168.67.0/24,127.0.0.0/8
' >>  /etc/postfix/main.cf

注释掉mydestination行,本文使用虚拟用户,此配置与其有冲突。

sed -i 's/^mydestination/^#mydestination/' /etc/postfix/main.cf

重启服务

service postfix restart

查看postfix支持的 SASL认证 插件类型:

postconf -a

#输出如下
cyrus
dovecot

 

验证postfix是否安装OK

#创建系统用户test
useradd test 
#测试登陆    
telnet 127.0.0.1 25

Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 Welcome to our mail.aolens.cn ESMTP,Warning: Version not Available!
helo
501 Syntax: HELO hostname
helo localhost
250 mail.mydomain.com
mail from:[email protected]    #发件者
250 2.1.0 Ok
rcpt to:test     #收件者,这里的收件者是前面创建的系统用户test
250 2.1.5 Ok
data
354 End data with .
Subject:aaa
aaaaaaa
.
250 2.0.0 Ok: queued as 2B78580CCB
quit
221 2.0.0 Bye
Connection closed by foreign host.

查看系统用户test收件内容

cat /var/spool/mail/test |tail

From [email protected]  Wed May 11 10:24:45 2016
Return-Path: 
X-Original-To: test
Delivered-To: [email protected]
Received: from localhost (localhost [127.0.0.1])
by mail.aolens.cn (Postfix) with SMTP id 2B78580CCB
for ; Wed, 11 May 2016 10:24:25 +0800 (CST)
Subject:aaa
Message-Id: <[email protected]>
Date: Wed, 11 May 2016 10:24:25 +0800 (CST)
From: [email protected]
aaaaaaa    

 

postfix开启基于cyrus-sasl的认证

添加配置到/etc/postfix/main.cf,让postfix启用saslauthd认证。

echo '
##=====================BASE========================= 
##postfix支持SMTP的认证saslauthd##
smtpd_banner = Welcome to our $myhostname SMTP
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
#smtpd_sasl_local_domain = ''
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
smtpd_client_restrictions = permit_sasl_authenticated
broken_sasl_auth_clients = yes
' >> /etc/postfix/main.cf
service postfix restart

 

再次测试

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.mydomain.com ESMTP,Warning: Version not Available!
ehlo mail.mydomain.com
250-mail.mydomain.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH NTLM LOGIN DIGEST-MD5 CRAM-MD5 PLAIN GSSAPI    #出现这两行代表已经支持认证,
250-AUTH=NTLM LOGIN DIGEST-MD5 CRAM-MD5 PLAIN GSSAPI    #前面的测试当中,没有此内容
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-DSN
250 CHUNKING

 

三、源码安装courier-authlib

下载 courier-unicode
wget https://sourceforge.net/projects/courier/files/courier-unicode/1.2/courier-unicode-2.1.tar.bz2/download --no-check-certificate

安装 courier-unicode

tar jxf courier-unicode-2.1.tar.bz2
cd courier-unicode-2.1
./configure
make && make install && echo 1

下载 courier-authlib

#下载页面:http://www.courier-mta.org/download.html#authlib
wget https://sourceforge.net/projects/courier/files/authlib/0.69.0/courier-authlib-0.69.0.tar.bz2/download --no-check-certificate
 

安装 courier-authlib

tar jxf courier-authlib-0.69.0.tar.bz2 -C /usr/local/src/
cd /usr/local/src/courier-authlib-0.69.0/

./configure \
--prefix=/usr/local/courier-authlib \
--sysconfdir=/etc \
--with-authmysql \
--with-mysql-libs=/usr/lib64/mysql \
--with-mysql-includes=/usr/include/mysql \
--with-RedHat \
--with-authmysqlrc=/etc/authmysqlrc \
--with-authdaemonrc=/etc/authdaemonrc \
--with-mailuser=postfix \
--with-mailgroup=postfix

make && make install && echo 1

配置 courier-authlib

修改目录权限

chmod -R 755 /usr/local/courier-authlib/var/spool/authdaemon

修改配置文件/etc/authdaemonrc

cp /etc/authdaemonrc.dist /etc/authdaemonrc
chown -R postfix.daemon   /etc/authdaemonrc
chmod -R 660              /etc/authdaemonrc

echo 'authmodulelist="authmysql"
authmodulelistorig="authmysql"
daemons=5
authdaemonvar=/usr/local/courier-authlib/var/spool/authdaemon
DEBUG_LOGIN=0
DEFAULTOPTIONS=""
LOGGEROPTS=""
' >> /etc/authdaemonrc

修改配置文件/etc/authmysqlrc

注意:该文件以'##'开头的行不要删掉,否则测试虚拟账户的时候会报错。

cp /etc/authmysqlrc.dist /etc/authmysqlrc
chown -R postfix.daemon  /etc/authmysqlrc
chmod -R 660             /etc/authmysqlrc

# 在原有配置下一行进行配置
sed -i '/\(^# \|^\)MYSQL_SERVER/a\MYSQL_SERVER  localhost'  /etc/authmysqlrc
sed -i '/\(^# \|^\)MYSQL_USERNAME/a\MYSQL_USERNAME  extmail'  /etc/authmysqlrc
sed -i '/\(^# \|^\)MYSQL_PASSWORD/a\MYSQL_PASSWORD  extmail'  /etc/authmysqlrc
sed -i '/\(^# \|^\)MYSQL_SOCKET/a\MYSQL_SOCKET  /opt/data/mysql/mysql.sock'  /etc/authmysqlrc
sed -i '/\(^# \|^\)MYSQL_PORT/a\MYSQL_PORT  3306'  /etc/authmysqlrc
sed -i '/\(^# \|^\)MYSQL_OPT/a\MYSQL_OPT  0'  /etc/authmysqlrc
sed -i '/\(^# \|^\)MYSQL_DATABASE/a\MYSQL_DATABASE  extmail'  /etc/authmysqlrc
sed -i '/\(^# \|^\)MYSQL_USER_TABLE/a\MYSQL_USER_TABLE  mailbox'  /etc/authmysqlrc
sed -i '/\(^# \|^\)MYSQL_CRYPT_PWFIELD/a\MYSQL_CRYPT_PWFIELD  password'  /etc/authmysqlrc
sed -i '/\(^# \|^\)MYSQL_UID_FIELD/a\MYSQL_UID_FIELD  1000'  /etc/authmysqlrc
sed -i '/\(^# \|^\)MYSQL_GID_FIELD/a\MYSQL_GID_FIELD  1000'  /etc/authmysqlrc
sed -i '/\(^# \|^\)MYSQL_LOGIN_FIELD/a\MYSQL_LOGIN_FIELD  username'  /etc/authmysqlrc
sed -i '/\(^# \|^\)MYSQL_HOME_FIELD/a\MYSQL_HOME_FIELD  concat('/var/mailbox/',homedir)'  /etc/authmysqlrc
sed -i '/\(^# \|^\)MYSQL_NAME_FIELD/a\MYSQL_NAME_FIELD  name'  /etc/authmysqlrc
sed -i '/\(^# \|^\)MYSQL_MAILDIR_FIELD/a\MYSQL_MAILDIR_FIELD  concat('/var/mailbox/',maildir)'  /etc/authmysqlrc

或者直接在文件末尾添加

echo "
MYSQL_SERVER          localhost
MYSQL_USERNAME        extmail
MYSQL_PASSWORD        extmail
MYSQL_SOCKET          /opt/data/mysql/mysql.sock
MYSQL_PORT            3306
MYSQL_OPT             0
MYSQL_DATABASE        extmail
MYSQL_USER_TABLE      mailbox
MYSQL_CRYPT_PWFIELD   password
MYSQL_UID_FIELD       1000
MYSQL_GID_FIELD       1000
MYSQL_LOGIN_FIELD     username
MYSQL_HOME_FIELD      concat('/var/mailbox/',homedir)
MYSQL_NAME_FIELD      name
MYSQL_MAILDIR_FIELD   concat('/var/mailbox/',maildir)
"  >>  /etc/authmysqlrc

#将需要的配置追加到文件末尾
#注意: 当使用echo    '    '    >> file 时,如果内部也有成对得单引号  '    '
#         最终写入文件的内容中的单引号会消失,如下面的concat('/var/mailbox/',homedir)
#         就成了 concat(/var/mailbox/,homedir),导致程序不识别。坑呀!!!!!!
#总之,这个/etc/authmysqlrc文件配置不对,虚拟账户测试时,就会失败。
 

创建邮件数据存储目录

mkdir -pv /var/mailbox
chown -R postfix.postfix /var/mailbox

添加courier-authlib为系统服务

cd /usr/local/src/courier-authlib-0.69.0
cp courier-authlib.sysvinit /etc/init.d/courier-authlib
chmod +x /etc/init.d/courier-authlib
chkconfig --add courier-authlib
chkconfig courier-authlib on
echo "/usr/local/courier-authlib/lib/courier-authlib/" >> /etc/ld.so.conf.d/courier-authlib.conf
ldconfig
service courier-authlib start

四、配置smtp

创建smtpd.conf,默认没有该文件

echo 'pwcheck_method: authdaemond
log_level: 3
mech_list: PLAIN LOGIN
authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket
' >> /etc/sasl2/smtpd.conf

 

五、配置Postfix使用虚拟用户

再次编辑/etc/postfix/main.cf

echo '
##=====================Vritual Mailbox settings=========================
##postfix支持虚拟用户##
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:1000
virtual_gid_maps = static:1000
virtual_transport = virtual
' >> /etc/postfix/main.cf

service postfix restart

 

六、Dovecot组件

配置dovecot

开启dovecot日志

echo 'log_path =  /var/log/dovecot.log
info_log_path =  /var/log/dovecot.info
log_timestamp = "%Y-%m-%d %H:%M:%S "
' >> /etc/dovecot/conf.d/10-logging.conf

开启虚拟邮箱

echo 'mail_location = maildir:/var/mailbox/%d/%n/Maildir' >> /etc/dovecot/conf.d/10-mail.conf
echo 'home_mailbox = Maildir/' >>  /etc/postfix/main.cf

创建/etc/dovecot/conf.d/auth-sql.conf

echo '
passdb {
  driver = sql
  args = /etc/dovecot/dovecot-sql.conf
}
userdb {
  driver = sql
  args = /etc/dovecot/dovecot-sql.conf
}
' >> /etc/dovecot/conf.d/auth-sql.conf


echo   'driver = mysql
connect = host=localhost dbname=extmail user=extmail password=extmail
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'
' >> /etc/dovecot/dovecot-sql.conf

chkconfig dovecot on
service dovecot start

七、Extmail组件

源码安装Extmail

tar zxf extmail-1.2.tar.gz
mkdir -p /var/www/extsuite/extmail
chown -R postfix.postfix /var/www/extsuite
cp -a extmail-1.2/* /var/www/extsuite/extmail
cp /var/www/extsuite/extmail/webmail.cf.default /var/www/extsuite/extmail/webmail.cf

修改Extmail主配置文件webmail.cf

详细参数可参见文章:https://blog.csdn.net/yetugeng/article/details/85314611

echo   '#manual modify
SYS_MESSAGE_SIZE_LIMIT = 5242880
SYS_USER_LANG = zh_CN
SYS_MAILDIR_BASE =  /var/mailbox
SYS_MYSQL_USER = extmail
SYS_MYSQL_PASS = extmail
SYS_MYSQL_DB = extmail
SYS_MYSQL_HOST = localhost
SYS_MYSQL_SOCKET = /opt/data/mysql/mysql.sock
SYS_AUTHLIB_SOCKET = /usr/local/courier-authlib/var/spool/authdaemon/socket
' >> /var/www/extsuite/extmail/webmail.cf

八、Extman组件

创建extmail库

注意:mysql的sql-mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION 要是这样的。

tar zxf extman-1.1.tar.gz

修改sql脚本

新版本的mysql已经不支持TYPE=MyISAM的写法了,而是使用ENGINE=MyISAM。

sed  -i  's/TYPE=MyISAM/ENGINE=MyISAM/'  extman-1.1/docs/extmail.sql

导入sql脚本

mysql -uroot -p < extman-1.1/docs/extmail.sql
mysql -uroot -p < extman-1.1/docs/init.sql
service postfix restart

安装extman

cp -a extman-1.1 /var/www/extsuite/extman
cp /var/www/extsuite/extman/webman.cf.default /var/www/extsuite/extman/webman.cf
chown -R postfix.postfix /var/www/extsuite/extman/cgi
chown -R postfix.postfix /var/www/extsuite/extmail/cgi

为extman创建临时目录

因为/tmp目录下的内容会定期清理,所以要么修改到其他位置,要么写个脚本检测/tmp/extman是否存在,不存在则创建。

mkdir /tmp/extman &&chown -R postfix.postfix /tmp/extman

修改ExtMan主配置文件webman.cf

关闭web登陆验证码功能

sed -i 's/SYS_CAPTCHA_ON = 1/SYS_CAPTCHA_ON = 0/'   /var/www/extsuite/extman/webman.cf

修改连接数据库的配置

echo 'SYS_MAILDIR_BASE = /var/mailbox
SYS_MYSQL_USER = extmail
SYS_MYSQL_PASS = extmail
SYS_MYSQL_DB = extmail
SYS_MYSQL_HOST = localhost
SYS_MYSQL_SOCKET = /opt/data/mysql/mysql.sock
' >>  /var/www/extsuite/extman/webman.cf

cmdserver设置为开机启动

不启动该进程的话,系统页面会出现Connection refused。

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

再次重启所有服务

service postfix restart
service dovecot restart
service saslauthd restart
service courier-authlib restart
service httpd restart

测试虚拟用户

/usr/local/courier-authlib/sbin/authtest -s login [email protected] extmail

Authentication succeeded.
Authenticated: [email protected]  (uid 1010, gid 1010)
Home Directory: /var/mailbox/extmail.org/postmaster
Maildir: /var/mailbox/extmail.org/postmaster/Maildir/
Quota: (none)
Encrypted Password: $1$phz1mRrj$3ok6BjeaoJYWDBsEPZb5C0
Cleartext Password: extmail
Options: (none)

#其中[email protected]是init.sql里自带的账户。

九、安装perl模块

extmail将会用到perl的Unix::syslogd功能,您可以去http://search.cpan.org搜索下载原码包进行安装。

tar zxf Unix-Syslog-1.1.tar.gz
cd Unix-Syslog-1.1/
perl Makefile.PL
make && make install

十、Apache组件

配置apache虚拟主机

echo '
#Listen 80
User postfix
Group postfix

#ServerName mail.mydomain.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

' >> /etc/httpd/conf/httpd.conf

service httpd restart

十一、配置域名的DNS记录

假设我的域名为mydomain.com,需要添加如下记录,下面的是例子,需要根据实际添加。

A记录

mail.mydomain.com

MX 记录

@ MX mail.mydomain.com

TXT记录 之 SPF 记录   

v=spf1 a mx ip4:yourip/mask -all

TXT记录 之 _dmarc记录  

v=DMARC1; p=quarantine; pct=5; rua=mailto:[email protected];ruf=mailto:[email protected]

TXT记录 之 default._domainkey记录 

参见文章  https://blog.csdn.net/yetugeng/article/details/83996397 进行配置

v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDXUVMcbWp0k4Mf3jnET8dTvkVVr/OdNbPjBi/u8cxEc+VyqZ0R+Pb2+0oWQinWV2YBzSodfVsQNMjjo8jFG8NO0uNXCJ/ZQIMoyo6QjscSnbWE/TGCZEeVCxj98+jcOjOneoXJ7ct19pGtON+MI3XK41u+emdo+68+A9N5lFT/HQIDADFR

 

最后

浏览器访问 http://服务器ip:80/ 或 http://mail.mydomain.com

选择"登陆邮箱管理",

默认的账号密码是:[email protected]/extmail*123*

 

 

 

附录:

postfix服务脚本

#!/bin/bash
#
# postfix      Postfix Mail Transfer Agent
#
# chkconfig: 2345 80 30
# description: Postfix is a Mail Transport Agent, which is the program \
#              that moves mail from one machine to another.
# processname: master
# pidfile: /var/spool/postfix/pid/master.pid
# config: /etc/postfix/main.cf
# config: /etc/postfix/master.cf
#
# Based on startup script from Simon J Mudd 
# 25/02/99: Mostly s/sendmail/postfix/g by John A. Martin 
# 23/11/00: Changes & suggestions by Ajay Ramaswamy 
# 20/01/01: Changes to fall in line with RedHat 7.0 style
# 23/02/01: Fix a few untidy problems with help from Daniel Roesen.

### BEGIN INIT INFO
# Provides: postfix MTA
# Required-Start: $local_fs $network $remote_fs
# Required-Stop: $local_fs $network $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop postfix
# Description: Postfix is a Mail Transport Agent, which is the program that 
#              moves mail from one machine to another.
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

RETVAL=0
prog="postfix"
lockfile=/var/lock/subsys/$prog
pidfile=/var/spool/postfix/pid/master.pid

ALIASESDB_STAMP=/var/lib/misc/postfix.aliasesdb-stamp

# Script to update chroot environment
CHROOT_UPDATE=/etc/postfix/chroot-update

status -p $pidfile -l $(basename $lockfile) -b /usr/libexec/postfix/master master >/dev/null 2>&1
running=$?

conf_check() {
    [ -x /usr/sbin/postfix ] || exit 5
    [ -d /etc/postfix ] || exit 6
    [ -d /var/spool/postfix ] || exit 5
}

make_aliasesdb() {
	if [ "$(/usr/sbin/postconf -h alias_database)" == "hash:/etc/aliases" ]
	then
		# /etc/aliases.db may be used by other MTA, make sure nothing
		# has touched it since our last newaliases call
		[ /etc/aliases -nt /etc/aliases.db ] ||
			[ "$ALIASESDB_STAMP" -nt /etc/aliases.db ] ||
			[ "$ALIASESDB_STAMP" -ot /etc/aliases.db ] || return
		/usr/bin/newaliases
		touch -r /etc/aliases.db "$ALIASESDB_STAMP"
	else
		/usr/bin/newaliases
	fi
}

start() {
	[ "$EUID" != "0" ] && exit 4
	# Check that networking is up.
	[ ${NETWORKING} = "no" ] && exit 1
	conf_check
	# Start daemons.
	echo -n $"Starting postfix: "
	make_aliasesdb >/dev/null 2>&1
	[ -x $CHROOT_UPDATE ] && $CHROOT_UPDATE
	/usr/sbin/postfix start 2>/dev/null 1>&2 && success || failure $"$prog start"
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch $lockfile
        echo
	return $RETVAL
}

stop() {
	[ "$EUID" != "0" ] && exit 4
	conf_check
        # Stop daemons.
	echo -n $"Shutting down postfix: "
	/usr/sbin/postfix stop 2>/dev/null 1>&2 && success || failure $"$prog stop"
	RETVAL=$?
	[ $RETVAL -eq 0 ] && rm -f $lockfile $pidfile
	echo
	return $RETVAL
}

reload() {
	conf_check
	echo -n $"Reloading postfix: "
	[ -x $CHROOT_UPDATE ] && $CHROOT_UPDATE
	/usr/sbin/postfix reload 2>/dev/null 1>&2 && success || failure $"$prog reload"
	RETVAL=$?
	echo
	return $RETVAL
}

abort() {
	conf_check
	/usr/sbin/postfix abort 2>/dev/null 1>&2 && success || failure $"$prog abort"
	return $?
}

flush() {
	conf_check
	/usr/sbin/postfix flush 2>/dev/null 1>&2 && success || failure $"$prog flush"
	return $?
}

check() {
	conf_check
	/usr/sbin/postfix check 2>/dev/null 1>&2 && success || failure $"$prog check"
	return $?
}

# See how we were called.
case "$1" in
  start)
	[ $running -eq 0 ] && exit 0
	start
	;;
  stop)
	[ $running -eq 0 ] || exit 0
	stop
	;;
  restart|force-reload)
	stop
	start
	;;
  reload)
	[ $running -eq 0 ] || exit 7
	reload
	;;
  abort)
	abort
	;;
  flush)
	flush
	;;
  check)
	check
	;;
  status)
	status -p $pidfile -l $(basename $lockfile) -b /usr/libexec/postfix/master master
	;;
  condrestart)
	[ $running -eq 0 ] || exit 0
	stop
	start
	;;
  *)
	echo $"Usage: $0 {start|stop|restart|reload|abort|flush|check|status|condrestart}"
	exit 2
esac

exit $?

 

参考文档:

extmail_solution概述:

http://wiki.extmail.org/%E5%A3%B9%E3%80%81extmail_solution%E6%A6%82%E8%BF%B0

Extmail软件官方下载地址:

http://www.extmail.org/download

Extmail邮件服务器centos搭建(一):

http://blog.51cto.com/aolens/1783870

Extmail邮件服务器centos搭建(二):

http://blog.51cto.com/aolens/1783878

 

发现一篇也是整理得比较详细的安装指导

https://www.cnblogs.com/sharesdk/p/9215606.html

你可能感兴趣的:(邮件)