为公司搭建的mail server,参考文件和故障记录
开始的安装,后来在其它系统添加用户验证时故障,后参考的http://yijiebuyi.com/blog/5388701a5ea536509abde3e274b8c4bd.html的参数进行的修改。
第一步
设置域名MX 解析
- 首先要有指定 ip 的 A 记录解析 @ A 111.111.111.111
- 需要有 mail 二级域名的 A 记录解析 mail A 111.111.111.111
- MX 记录解析 @ MX mail.yijiebuyi.cn.
- TXT解析 @ TXT v=spf1 include:spf.mail.yijiebuyi.com ~all
第二步
//停止 sendmail 服务
/etc/init.d/sendmail stop
//卸载 sendmail 服务
yum remove sendmail
第三步
安装 postfix 和 dovecot
yum install postfix dovecot
第四步
安装 cycus-sasl
yum install cyrus-sasl-*
第五步
配置 postfix
vim /etc/postfix/main.cf
myhostname=mail.yijiebuy.com //这里要换成你自己的邮箱服务器
mydomain=yijiebuyi.com //这里换成你自己的主机服务器
myorigin = $mydomain
inet_interfaces = all #可以接收所有域名的邮件
inet_protocols = ipv4
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,mail.$mydomain, www.$mydomain, ftp.$mydomain
local_recipient_maps =
mynetworks =0.0.0.0/0 #设置内网ip
relay_domains = $mydestination
home_mailbox = Maildir/
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions = permit_sasl_authenticated,reject_unauth_destination,permit_mynetworks
smtpd_client_restrictions = permit_sasl_authenticated
第六步
配置 dovecot
vim /etc/dovecot/dovecot.conf
protocols = imap pop3 lmtp
listen = *
vim /etc/dovecot/conf.d/10-auth.conf
disable_plaintext_auth = no
auth_mechanisms = plain
vim /etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:~/Maildir
vim /etc/dovecot/conf.d/10-ssl.conf
ssl = no
第七步
配置 sasl2
vim /etc/sysconfig/saslauthd
MECH=shadow #指定以本地系统用户名认证
vim /usr/lib64/sas12/smtpd.conf //64位系统 vim /usr/lib/sas12/smtpd.conf //32位系统
pwcheck_method: saslauthd
mech_list: PLAIN LOGIN
log_level:3
第八步
启动服务
启动 postfix ,dovecot ,saslauthd 服务
service postfix start
service dovecot start
service saslauthd start
注意: centOS 7下将不再使用 service 来启动服务,而是跳转到 systemctl 指令下.
下面我们使用 systemctl 来启动上面的3个服务
systemctl start dovecot
systemctl start postfix
systemctl start saslauthd
如何查看 saslauthd 命令是否启动服务成功,使用 status 来查看.
systemctl status postfix
● postfix.service - Postfix Mail Transport Agent
Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2016-05-23 18:29:21 CST; 20h ago
上面的提示信息告诉 postfix 服务正在运行中.
第九步
创建新账号
添加账户 admin
[root@10-10-126-106 ~]# useradd admin
为帐号 admin 创建密码
[root@10-10-126-106 ~]# passwd test
Changing password for user test.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
第十步
配置客户端
我本地mail客户端是 mac 下的 foxmail ,选择添加账户 admin
上面的 pop3 和 smtp 服务器为第一步中配置的MX解析记录: mail.yijiebuyi.com
然后重复 第九步 和第十步 添加测试帐号 soso@yijiebuyi.com
第十一步
发送邮件
目前我的 foxmail 客户端添加了如下邮箱帐号 其中 admin 和 soso 是 mail.yijiebuyi.com 邮箱服务器下配置的测试帐号.
尝试用 soso@yijiebuyi.com 发送邮件给 admin@yijiebuyi.com admin帐号收件箱:
soso帐号发件箱:
后来,发现saslauthd服务无法启动,参考http://ju.outofmemory.cn/entry/12533文章,发现配置文件错误,修改后启动成功,公司使用的工单系统测试通过。
testsaslauthd “authentication failed” 解决办法
当我们配置好邮件服务器,服务器也开始运行了,但我们要对外进行邮件服务就需要对服务器进行域名绑定。
首先我们要做一个名为mail.j8.mu的A纪录,地址指向邮件服务器的IP
然后我们做一个头为空的MX纪录,如j8.mu,地址指向刚刚做好的A纪录,mail.j8.mu
这样,等域名解析生效,就我们的邮件服务就可以外面访问了。
在测试sasl做用户验证时报错0: NO “authentication failed”
[root@mail ~]# testsaslauthd -u test -p ’123456′0: NO “authentication failed”
[reason=PAM auth error]Apr 12 11:43:27 mail saslauthd[19763]: do_auth : auth failure:
[user=test] [service=imap] [realm=] [mech=pam] [reason=PAM auth error]
解决办法
将/etc/sysconfig/saslauthd中MECH=PAM改为shadow,并重启sasl服务。
[root@mail locale]# vi /etc/sysconfig/saslauthd
# Directory in which to place saslauthd’s listening socket, pid file, and so
# on. This directory must already exist.
SOCKETDIR=/var/run/saslauthd
# Mechanism to use when checking passwords. Run “saslauthd -v” to get a list
# of which mechanism your installation was compiled with the ablity to use.
MECH=shadow
# Options sent to the saslauthd. If the MECH is other than “pam” uncomment the next line.
# DAEMONOPTS=–user saslauth
# Additional flags to pass to saslauthd on the command line. See saslauthd(8)
# for the list of accepted flags.
FLAGS=
[root@mail locale]# service saslauthd restart
停止 saslauthd: [确定]
正在启动 saslauthd: [确定]
测试验证成功!
[root@mail locale]# testsaslauthd -u test -p ‘sandsand’
: OK “Success.”


浙公网安备 33010602011771号