邮件服务器(postfix+devocot+cyrus-sasl+centos7)

说明

参考网络上其他人文章。将他人技术文章亲自测试并总结补充。
搭建邮件服务器需要有一台公网服务器和域名
本文使用10.10.10.10代替实际公网ip,使用a.com代替实际域名

邮件器搭建

1 . 邮件服务器域名解析(主要参数)

记录类型 主机记录 记录值
A @ 10.10.10.10
A mail 10.10.10.10
MX @ mail.a.com
TXT @ v=spf1 inuyi.cspf.mail.a.com ~all
2 .安装相关软件
卸载 sendmail 服务(看到网上有文章说这个不好用,那就卸载了吧)
1
2
/etc/init.d/sendmail stop     #//停止 sendmail 服务
yum remove sendmail #//卸载 sendmail 服务
安装 postfix 和 dovecot
1
yum install postfix dovecot
安装 cycus-sasl
1
yum install cyrus-sasl-*
3 .配置相关软件
配置 postfix
1
vim /etc/postfix/main.cf

按照以下进行配置,将前面的#号去掉并修改参数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
myhostname=mail.a.com             #这里要换成你自己的邮箱服务器
mydomain=a.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

1
2
3
4
vim /etc/dovecot/dovecot.conf
####修改如下内
protocols = imap pop3 lmtp
listen = *
1
2
3
4
vim /etc/dovecot/conf.d/10-auth.conf
####修改如下内
disable_plaintext_auth = no
auth_mechanisms = plain
1
2
3
vim /etc/dovecot/conf.d/10-mail.conf
####修改如下内
mail_location = maildir:~/Maildir
1
2
3
vim /etc/dovecot/conf.d/10-ssl.conf
####修改如下内
ssl = no

配置 sasl2

1
2
3
vim /etc/sysconfig/saslauthd
####修改如下内
MECH=shadow #指定以本地系统用户名认证
1
2
3
4
5
vim /usr/lib64/sas12/smtpd.conf    //64位系统
####修改如下内,如果没有文件,自行创建该目录和文件
pwcheck_method: saslauthd
mech_list: PLAIN LOGIN
log_level:3

4 .启动服务
启动

1
2
3
systemctl  start  dovecot
systemctl start postfix
systemctl start saslauthd

停止

1
2
3
systemctl  stop dovecot
systemctl stop postfix
systemctl stop saslauthd

查看状态,出现如下启动成功

1
systemctl status postfix


5 .客户端配置,收发邮件测试
因为使用系统用户为账号要创建一个新账号

1
useradd adminmail

修改密码

1
passwd adminmail      #输入两次密码账号创建完成

配置客户端(本文使用Foxmail)


红色框内输入自己的配置信息(因为没有配置证书,不用勾选ssl)


发送测试


我的126邮箱客户端在手机上,已经收到邮件。

回复一下邮件,测试服务器能收到邮件



说两句

经过测试给126邮箱发送邮件可以成功,给QQ邮箱发送出现点问题。返回我如下信息,可能是配置问题?腾讯给拦截了?,有兴趣的同学自己找找解决方案(本文不深入查找了)。