码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-05-27 18:40:14      阅读:456      评论:0      收藏:0      [点我收藏+]

标签:邮件服务器   认证   

接上一篇Extmail博文继续 https://www.aolens.cn/?p=1018

3.3 postfix开启基于cyrus-sasl的认证

查看sasl有关的安装包

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

cyrus-sasl-md5-2.1.23-15.el6_6.2.x86_64

cyrus-sasl-2.1.23-15.el6_6.2.x86_64

cyrus-sasl-plain-2.1.23-15.el6_6.2.x86_64

cyrus-sasl-lib-2.1.23-15.el6_6.2.x86_64

cyrus-sasl-gssapi-2.1.23-15.el6_6.2.x86_64

cyrus-sasl-devel-2.1.23-15.el6_6.2.x86_64

3.3.1

postfix和sasl结合,编辑postfix配置文件

[root@mail ~]# vim /etc/postfix/main.cf
 
#添加一下配置
 
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 SMTP
 
[root@mail ~]# service postfix restart
 
关闭 postfix:                                             [确定]
 
启动 postfix:                                             [确定]
 
[root@mail ~]# 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.aolens.cn ESMTP,Warning: Version not Available!
 
ehlo mail.aolens.cn
 
250-mail.aolens.cn
 
250-PIPELINING
 
250-SIZE 10240000
 
250-VRFY
 
250-ETRN
 
250-AUTH CRAM-MD5 DIGEST-MD5 PLAIN LOGIN GSSAPI
 
250-AUTH=CRAM-MD5 DIGEST-MD5 PLAIN LOGIN GSSAPI
 
250-ENHANCEDSTATUSCODES
 
250-8BITMIME
 
250 DSN

3.3.2 sasl配置

[root@mail ~]# service saslauthd restart
 
停止 saslauthd:                                           [确定]
 
正在启动 saslauthd:                                       [确定]
 
[root@mail ~]# chkconfig --add saslauthd
 
[root@mail ~]# chkconfig saslauthd on

3.4  安装Courier authentication library

下载地址:http://www.courier-mta.org/download.html#authlib

[root@mail ~]# tar jxf courier-authlib-0.66.4.tar.bz2 -C /usr/local/src/
 
[root@mail ~]# cd /usr/local/src/courier-authlib-0.66.4/
 
[root@mail /usr/local/src/courier-authlib-0.66.4]# ./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

报错:

configure: error: The Courier Unicode Library 1.2 appears not to be installed. You may need to install a separate development subpackage, in addition to the main package

下载:courier-unicode

https://sourceforge.net/projects/courier/files/courier-unicode/1.2/courier-unicode-1.2.tar.bz2/download

[root@mail ~]# tar jxf courier-unicode-1.2.tar.bz2
 
[root@mail ~]# cd courier-unicode-1.2
 
[root@mail ~/courier-unicode-1.2]# ./configure
 
[root@mail ~/courier-unicode-1.2]# make && make install && echo 1

再次编译courier-authlib就好了

3.4.2 配置courier-authlib

[root@mail /usr/local/src/courier-authlib-0.66.4]# chmod -R 755 /usr/local/courier-authlib/var/spool/authdaemon
 
[root@mail /usr/local/src/courier-authlib-0.66.4]# cp /etc/authdaemonrc.dist /etc/authdaemonrc
 
[root@mail /usr/local/src/courier-authlib-0.66.4]# cp /etc/authmysqlrc.dist /etc/authmysqlrc
 
[root@mail /usr/local/src/courier-authlib-0.66.4]# vim /etc/authdaemonrc
 
#authmodulelist="authuserdb authpwd authshadow authmysql authcustom authpipe”
 
#authmodulelistorig="authuserdb authpwd authshadow authmysql authcustom authpipe"
 
authmodulelist="authmysql"
 
authmodulelistorig="authmysql"
 
MYSQL_SERVER        localhost
 
MYSQL_USERNAME      root
 
MYSQL_PASSWORD      aolens
 
MYSQL_SOCKET      /var/lib/mysql/mysql.sock
 
MYSQL_PORT      3306
 
MYSQL_DATABASE      extmail
 
MYSQL_USER_TABLE    mailbox
 
MYSQL_CRYPT_PWFIELD password
 
DEFAULT_DOMAIN        aolens.cn
 
MYSQL_UID_FIELD     ‘2525‘
 
MYSQL_GID_FIELD     ‘2525‘
 
MYSQL_LOGIN_FIELD   username
 
MYSQL_HOME_FIELD    concat(‘/var/mailbox/‘,homedir)
 
MYSQL_MAILDIR_FIELD   concat(‘/var/mailbox/‘,maildir)
 
 
 
[root@mail /usr/lib64/sasl2]# mkdir -pv /var/mailbox
 
mkdir: 已创建目录 "/var/mailbox"
 
[root@mail /usr/lib64/sasl2]# chown -R postfix.postfix /var/mailbox

为courier-authlib创建启动脚本

[root@mail /usr/local/src/courier-authlib-0.66.4]# cp courier-authlib.sysvinit /etc/init.d/courier-authlib
 
[root@mail /usr/local/src/courier-authlib-0.66.4]# chmod +x /etc/init.d/courier-authlib
 
[root@mail /usr/local/src/courier-authlib-0.66.4]# chkconfig --add courier-authlib
 
[root@mail /usr/local/src/courier-authlib-0.66.4]# chkconfig courier-authlib on
 
[root@mail /usr/local/src/courier-authlib-0.66.4]# echo "/usr/local/courier-authlib/lib/courier-authlib/" >> /etc/ld.so.conf.d/courier-authlib.conf
 
[root@mail /usr/local/src/courier-authlib-0.66.4]# ldconfig
 
[root@mail /usr/local/src/courier-authlib-0.66.4]# service courier-authlib startStarting Courier authentication services: authdaemond

3.4.3配置smtp以及虚拟用户的相关

创建smtpd.conf

pwcheck_method: authdaemond
 
log_level: 3
 
mech_list: PLAIN LOGIN
 
authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket

编辑main.cf

##postfix支持SMTP##
 
broken_sasl_auth_clients = yes
 
smtpd_client_restrictions = permit_sasl_authenticated
 
smtpd_sasl_security_options = noanonymous
 
smtpd_sasl_auth_enable = yes
 
smtpd_sasl_local_domain = $myhostname
 
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
 
##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:2525
 
virtual_gid_maps = static:2525
 
virtual_transport = virtual

3.5 导入数据库

使用extman源码目录下docs中的extmail.sql和init.sql建立数据库:

下载extmail 和extman

http://7xivyw.com1.z0.glb.clouddn.com/extmail-1.2.tar.gz

http://7xivyw.com1.z0.glb.clouddn.com/extman-1.1.tar.gz

[root@mail ~/extman-1.1/docs]# cp mysql_virtual_* /etc/postfix/

创建数据库

[root@mail ~/extman-1.1/docs]# mysql -uroot -p < extmail.sql
 
[root@mail ~/extman-1.1/docs]# mysql -uroot -p < init.sql
 
[root@mail ~/extman-1.1/docs]# service postfix restart
 
关闭 postfix:                                             [确定]
 
启动 postfix:                                             [确定]

3.6 配置dovecot

[root@mail ~/extman-1.1/docs]# vim /etc/dovecot/conf.d/10-mail.conf
 
#添加
 
mail_location = maildir:/var/mailbox/%d/%n/Maildir
 
[root@mail ~/extman-1.1/docs]# vim /etc/postfix/main.cf
 
#添加
 
home_mailbox = Maildir/
 
[root@mail /etc/dovecot/conf.d]# cp  auth-sql.conf.ext auth-sql.conf
 
[root@mail /etc/dovecot/conf.d]# vim auth-sql.conf
 
#修改
 
passdb {
 
driver = sql
 
#args = /etc/dovecot/dovecot-sql.conf.ext
 
args = /etc/dovecot/dovecot-sql.conf
 
}
 
userdb {
 
driver = sql
 
#args = /etc/dovecot/dovecot-sql.conf.ext
 
args = /etc/dovecot/dovecot-sql.conf
 
}

创建dovecot-mysql.conf

[root@mail /etc/dovecot/conf.d]# vim /etc/dovecot/dovecot-mysql.conf
 
driver = mysql
 
connect = host=localhost dbname=extmail user=root password=aolens
 
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‘
 
[root@mail /etc/dovecot]# service dovecot start
 
正在启动 Dovecot Imap:                                    [确定]
 
[root@mail /etc/dovecot]# chkconfig dovecot on

3.7 安装Extmail

[root@mail ~]# tar zxf extmail-1.2.tar.gz
 
[root@mail ~]# cp -a extmail-1.2 /var/www/extsuite/extmail
 
[root@mail ~]# cd /var/www/extsuite/extmail
 
[root@mail /var/www/extsuite/extmail]# cp webmail.cf.default webmail.cf

3.7.2 修改主配置文件

SYS_MESSAGE_SIZE_LIMIT = 5242880   #用户可以发送的最大邮件
 
SYS_USER_LANG = zh_CN   #语言选择
 
SYS_MAILDIR_BASE =  /var/mailbox #邮件存放位置
 
SYS_MYSQL_USER = root   #数据库配置
 
SYS_MYSQL_PASS = aolens
 
SYS_MYSQL_DB = extmail
 
SYS_MYSQL_HOST = localhost
 
SYS_MYSQL_SOCKET = /var/lib/mysql/mysql.sock
 
SYS_AUTHLIB_SOCKET = /usr/local/courier-authlib/var/spool/authdaemon/socket

3.8安装extman

[root@mail ~]# cp -a extman-1.1 /var/www/extsuite/extman
 
[root@mail /var/www/extsuite/extman]# cp webman.cf.default webman.cf
 
[root@mail /var/www/extsuite/extman]# chown -R postfix.postfix /var/www/extsuite/extman/cgi
 
[root@mail /var/www/extsuite/extman]# chown -R postfix.postfix /var/www/extsuite/extmail/cgi
 
为extman创建临时目录
 
[root@mail /var/www/extsuite/extman]# mkdir /tmp/extman &&chown -R postfix.postfix /tmp/extman
 
[root@mail /var/www/extsuite/extman]# vim webman.cf
 
SYS_CAPTCHA_ON = 0   #修改1为0 验证码功能
 
[root@mail /var/www/extsuite/extman]# service postfix restart
 
关闭 postfix:                                             [确定]
 
启动 postfix:                                             [确定]
 
[root@mail /var/www/extsuite/extman]# service dovecot restart
 
停止 Dovecot Imap:                                        [确定]
 
正在启动 Dovecot Imap:                                    [确定]
 
[root@mail /var/www/extsuite/extman]# service saslauthd restart
 
停止 saslauthd:                                           [确定]
 
正在启动 saslauthd:                                       [确定]

3.9测试虚拟用户

[root@mail ~]# /usr/local/courier-authlib/sbin/authtest -s login postmaster@extmail.org extmail
 
Authentication succeeded.
 
Authenticated: postmaster@extmail.org  (uid 2525, gid 2525)
 
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)

postmaster@extmail.org时init.sql里自带的

4 安装perl依赖环境

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

[root@mail ~]# tar zxf Unix-Syslog-1.0.tar.gz -C /usr/local/src/
 
[root@mail ~]# cd /usr/local/src/Unix-Syslog-1.0/
 
[root@mail /usr/local/src/Unix-Syslog-1.0]# perl Makefile.PL
 
[root@mail /usr/local/src/Unix-Syslog-1.0]# make && make install

4.2 配置apache虚拟主机

[root@mail ~]# vim /etc/httpd/conf/httpd.conf
 
User postfix
 
Group postfix
 
<VirtualHost *:80>
 
ServerName mail.aolens.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
 
</VirtualHost>
 
[root@mail ~]# service httpd restart

访问mail.aolens.cn

选择登陆邮箱管理:默认的账号密码是:root@extmail.org   extmail*123*

技术分享

添加域,添加用户

使用普通用户登录

报错:

Can‘t chdir to /var/mailbox/aolens.cn/aolens/Maildir/, No such file or directory

[/shell][root@mail /var/www/extsuite]# vim /var/www/extsuite/extman/webman.cf

SYS_MAILDIR_BASE = /var/mailbox

SYS_MYSQL_USER = root

SYS_MYSQL_PASS = aolens

SYS_MYSQL_DB = extmail

SYS_MYSQL_HOST = localhost

SYS_MYSQL_SOCKET = /var/lib/mysql/mysql.sock[/shell]

就是因为webman.cf没有设置导致创建用户后没有自动创建用户邮件存放路径。

不启动cmdserver 的话系统页面会出现Connection refused

技术分享

[root@mail /var/www/extsuite/extman/daemon]# ./cmdserver -d

loaded ok

现在尝试发送邮件:

aaa@aolens.cn —> 312313231@qq.com  邮件发送成功

aaa@aolens.cn —> bbb@aolens.cn 发送不成功

报错:

mail postfix/smtpd[6525]: NOQUEUE: reject: RCPT from localhost[127.0.0.1]: 550 5.1.1 <bbb@aolens.cn>: Recipient address rejected: User unknown in local recipient table; from=<aaa@aolens.cn> to=<bbb@aolens.cn> proto=ESMTP helo=<localhost.localdomain>

修改main.cf

mydestination = $myhostname

邮件发送成功!




本文出自 “aolens·程超” 博客,请务必保留此出处http://aolens.blog.51cto.com/7021142/1783878

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

标签:邮件服务器   认证   

原文地址:http://aolens.blog.51cto.com/7021142/1783878

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!