一、说明
postfix 发送邮件
devocot 接收邮件(待续)
cyrus-sasl smtp认证(用户邮箱+密码)
搭建之前请了解邮件传输过程,了解MUA,MTA,MDA和MRA的概念
邮箱原理介绍:https://blog.csdn.net/yatum_2014/article/details/79734428
二、环境
centos7
三、需要安装的软件
postfix
cyrus-sasl
vim
mailx
四、步骤
-
卸载sendmail
rpm -qa | grep sendmail /etc/init.d/sendmail stop #//停止 sendmail 服务 yum remove sendmail #//卸载 sendmail 服务
-
安装postfix
yum -y install postfix //centos7 默认已经安装postfix
-
安装cyrus-sasl
yum -y install cyrus-sasl-*
-
配置 postfix
vim /etc/postfix/main.cf 以下已在配置文件中存在,修改: #这里要换成你自己的邮箱服务器 myhostname=mail.xt.dhdc.com # 邮箱域名 mydomain=xt.dhdc.com # 发送邮件的域名 myorigin = $mydomain # 可以接收所有域名的邮件 inet_interfaces = all inet_protocols = all # 以下域名会被接收处理 mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,mail.$mydomain, www.$mydomain, ftp.$mydomain # 邮箱目录 home_mailbox = Maildir/ 以下在结尾新增: smtpd_sasl_auth_enable = yes smtpd_sasl_local_domain = $myhostname smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination smtpd_client_restrictions = permit_sasl_authenticated broken_sasl_auth_clients = yes smtpd_sasl_path = smtpd smtpd_sasl_security_options = noanonymous smtpd_sasl_authenticated_header = yes message_size_limit = 15728640
-
配置cyrus-sasl
vim /etc/sysconfig/saslauthd ####修改如下内 MECH=shadow #指定以本地系统用户名认证 vim /etc/sasl2/smtpd.conf pwcheck_method: saslauthd mech_list: plain login
-
启动服务
systemctl start postfix systemctl enable postfix // 开机启动 systemctl start saslauthd systemctl enable saslauthd // 开机启动
-
配置saslauthd对用户密码文件/etc/shadow的永久读取权限
必须配置,否则smtp认证会失败
setsebool -P saslauthd_read_shadow on
-
测试
测试cyrus-sasl smtp认证 testsaslauthd -u 'root' -p '123456' 安装mailx测试: yum -y install mailx echo '测试邮件内容' | mail -s '测试主题!' 498922984@qq.com // 邮箱收到邮件说明发件成功
五、问题总结
-
fatal no sasl authentication
systemctl status postfix 出现错误: fatal no sasl authentication 解决办法: 1 仔细检查cyrus-sasl配置文件,/etc/sysconfig/saslauthd /etc/sasl2/smtpd.conf 2依然有问题,卸载cyrus-sasl,重装 yum remove cyrus-sasl yum install cyrus-sasl-*
-
0: NO “authentication failed”
testsaslauthd -u 'root' -p '123456', 出现报错: 0: NO "authentication failed" 解决办法:参考步骤【7】
-
查看错误日志
vi /var/log/maillog vi /var/log/messages