1、 启动 saslauthd 认证服务
[root@mail ~]# yum -y install cyrus-sasl //此包默认通常已安装
[root@mail ~]# systemctl restart saslauthd
[root@mail ~]# systemctl enable saslauthd
[root@mail ~]# testsaslauthd -u user01 -p test1234 -s smtp
0: OK "Success." //检查saslauthd服务
2、编辑 postfix 配置,启用SMTP认证
[root@mail ~]# vim /etc/postfix/main.cf
# 设置本地网络
mynetworks = 127.0.0.1
# 启用SASL认证
smtpd_sasl_auth_enable = yes
# 阻止匿名发信
smtpd_sasl_security_options = noanonymous
# 拒绝向未授权的目标域发信
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
[root@mail ~]# systemctl restart saslauthd
3、以用户user01为例,未经过认证登录时,向外域发邮件会被拒绝
[root@mail ~]# telnet mail.auto.com 25
Trying 127.0.0.1...
Connected to mail.auto.com (127.0.0.1).
Escape character is '^]'.
220 mail.xxx.com ESMTP Postfix
HELO localhost // 宣告本机地址
250 mail.auto.com
MAIL FROM:user01@auto.com // 指定发件人地址
250 2.1.0 Ok
RCPT TO:test@126.com // 指定收件人地址
454 4.7.1 <test@126.com>: Relay access denied
// 发送外域的发信请求被拒绝
quit // 断开telnet连接
221 2.0.0 Bye
Connection closed by foreign host.
[root@mail ~]# printf "user01" | openssl base64
bmljaw==
[root@mail ~]# printf "test1234" | openssl base64
MTIzNDU2Nw==
[root@mail ~]# telnet mail.auto.com 25
Trying 127.0.0.1...
Connected to mail.xxx.com (127.0.0.1).
Escape character is '^]'.
220 mail.xxx.com ESMTP Postfix
EHLO localhost //加密宣告本机地址
250-mail.xxx.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
AUTH LOGIN //声明要执行认证登录
334 VXNlcm5hbWU6
bmljaw== //输入用户名xxx的BASE64编码
334 UGFzc3dvcmQ6
MTIzNDU2Nw== //输入密码1234567的BASE64编码
235 2.7.0 Authentication successful
MAIL FROM:user01@xxx.com //指定发件人地址
250 2.1.0 Ok
RCPT TO:test@126.com //指定收件人地址
250 2.1.5 Ok
DATA //开始编写邮件内容
354 End data with <CR><LF>.<CR><LF>
Subject:SMTP Auth Test //指定邮件标题
Hello, here is a test mail. //输入文本邮件内容
. //独立的 . 表示输入完毕
250 2.0.0 Ok: queued as 8C48431D8B2
quit //断开telnet连接
221 2.0.0 Bye
Connection closed by foreign host.
本文由来源 jackaroo2020,由 javajgs_com 整理编辑,其版权均为 jackaroo2020 所有,文章内容系作者个人观点,不代表 Java架构师必看 对观点赞同或支持。如需转载,请注明文章来源。