第一次建立自己单位的mail服务器。根据网上的资料都无法通过md5加密口令的smtp认证。自己改动了几个地方,终于实现了。
从网上得到了很多资料,这次回报一下,有什么不对的地方,请大家指出。
首先你可以网上搜一下完整的PHP APACHE MYSQL DOVECOT POSTFIX的安装事项,再看看这篇能不能解决你遇到的问题。
服务器版本:CentOS 4.5 X86_64
其它的相关软件都是最新版本
1.安装PHP的时候,在configure的时候,加上 --with-mycrypt --with-hash ,网上有安装的方法;
2.安装好mysql , 我的mysql装在 /db/mysql
3.创建相应的用户和工作组
#groupadd -g 2002 postfix
#groupadd -g 2003 postdrop
#useradd -u 2002 -g 2002 -G postdrop -d /dev/null -s /sbin/nologin postfix
#useradd -d /dev/null -s /sbin/nologin dovecot
4.安装dovecot
#./configure --prefix=/usr/local/dovecot --sysconfdir=/etc/dovecot --with-sql --with-sql-drivers --with-mysql
#make && make install
配置dovecot.conf
#cd /etc/dovecot
#cp dovecot-example.conf dovecot.conf
#vi dovecot.conf
base_dir=/var/run/dovecot
protocols=imap imaps pop3 pop3s
listen=*
disable_plaintext_auth = no
ssl_disable = yes
mail_location = maildir:/mail/%d/%n //服务器邮箱的统一位置,maildir格式,如/mail/xyz.com/username
pop3_uidl_format=%08Xu%08Xv
auth default {
...
mechanisms = PLAIN LOGIN CRAM-MD5 DIGEST-MD5
passdb sql { //去掉注释
args = /etc/dovecot/dovecot-sql.conf
}
...
userdb sql {//去掉注释
args = /etc/dovecot/dovecot-sql.conf
}
...
socket listen {
...
client {
path = /var/run/dovecot/auth-client //postfix依靠dovecot 实现 SMTP AUTH 时要用,在postfix中的main.cf配置文件中的smtpd_sasl_path=要引用这项
mode = 0660
user = postfix
group = postfix
}
}
}
配置dovecot-sql.conf
#cp dovecot-sql-example.conf dovecot-sql.conf
#vi dovecot-sql.conf
driver = mysql
connect = host=localhost dbname=postfix user=postfix password=postfixPnp1993
default_pass_scheme=MD5 //改成PLAIN-MD5 后就不会与postfixadmin生成的密码兼容,除非使用下面介绍的修改postfixadmin,
//dovecot的加密方式见
//关键的地方的,搞了好一阵子。初始是,邮件地址: pop3账号username,会出现密码不正确,除非pop3账号也填 ,否则登陆不上。其实就是PASSWORD_QUERY的代码,改后就可以了,怪的是用where username='%u' 也不可以!!只能substring一下了
password_query = select username as user,password from mailbox where substring(username,1,instr(username,'@')-1) = '%n' And active='1'
user_query = select maildir as home,2002 as uid ,2002 as gid from mailbox where username='%u' And active='1'
创建符号链接
#ln -s /usr/local/dovecot/sbin/dovecot /usr/bin/dovecot
5.安装postfixadmin 以及里面的DATABASE_MYSQL.TXT同,网上有很多
6.安装postfix
解压postfix的邮箱限额补丁,如网上介绍
#gzip -d postfix-2.4.1-vda-ng.patch.gz
#cp postfix-2.4.1-vda-ng.patch postfix-2.4.1
#cd postfix-2.4.1
#patch -p1 < postfix-2.4.1-vda-ng.patch
#如下编译
#看这里Postfix SASL Howto
#make -f Makefile.init makefiles \
'CCARGS=-DHAS_MYSQL -I/db/mysql/include/mysql \
-DUSE_TLS -DUSE_SASL_AUTH -DDEF_SERVER_SASL_TYPE=\"dovecot\"' \
'AUXLIBS=-L/db/mysql/lib/mysql -lmysqlclient -lz -lm'
#make
#make install //一切按照缺省的就行了,可以把tmp设置成/tmp/postfix
#mv /etc/aliases /etc/aliases.old
#ln -s /etc/postfix/aliases /etc/aliases
#/usr/bin/newaliases
#vi /etc/postfix/main.cf
myhostname = mail.xyz.com ##不能与mysql里的domain重名
mydomain = xyz.com
myorigin = $mydomain
mydestination = $myhostname localhost localhost.$mydomain #一定不要出现与MYSQL->postfix->domain表中重名的 如:$mydomain,所以我就选这行
mynetworks = 127.0.0.0/8
inet_interfaces = all
home_mailbox=Maildir/
#=====================Vritual Mailbox settings=========================
virtual_mailbox_base = /mail/
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:2002
virtual_gid_maps = static:2002
virtual_transport = virtual
#====================QUOTA========================
message_size_limit = 52428800 //每个邮件最大尺寸50M
mailbox_size_limit = 209715200 //邮箱大小限制200M
virtual_mailbox_limit = 209715200
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_overquota_bounce = yes
#====================SASL ESMTP Authenticat=================
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot //用dovecot进行认证
smtpd_sasl_path = /var/run/dovecot/auth-client //与dovecot.conf中如下的的path一致,前面讲过
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions = permit_mynetworks, //注意,后面到smtpd_sals_local_domain的每一行前面都有一个空格
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_local_domain =
smtpd_sasl_security_options = noanonymous
smtpd_banner=$myhostname ESMTP
查看master.cf文件必须包含下面一行
virtual unix - n n - - virtual
编辑/etc/postfix/mysql_virtual_alias_maps.cf 为以下内容
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = alias
select_field = goto
where_field = address
编辑/etc/postfix/mysql_virtual_domains_maps.cf 为以下内容
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = domain
select_field = description
where_field = domain
编辑/etc/postfix/mysql_virtual_mailbox_limit_maps.cf 为以下内容
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = mailbox
select_field = quota
where_field = username
编辑/etc/postfix/mysql_virtual_mailbox_maps.cf 为以下内容
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = mailbox
select_field = maildir
where_field = username
如果你在dovecot-sql.conf中用的是default_pass_scheme=PLAIN-MD5,就要修改postfixadmin中的functions.inc.php的函数pacrypt
function pacrypt($pw,$pw_db){
//加入普通的md5加密
if ($CONF['encrypt']=='md5'){
$password=md5($pw);
}
}
//同时也要改其它相关webmail操作中的有关加密password一项
修改config.inc.php
$CONF['encrypt']='md5';
如果你在dovecot-sql.conf中用的是default_pass_scheme=MD5 ,就不需要修改任何地方
好了,使用postfixadmin创建域和帐号
域:xyz.com
用户:test
启动
echo "" > /var/log/maillog
dovecot
postfix start
vi /var/log/maillog
看有没有错误
在客户端用outlook,foxmail,选中发信时服务器需要验证 SMTP AUTH, 测试一下。
阅读(1019) | 评论(0) | 转发(0) |