Linux-Postfix+Dovecot+Postfixadmin+Roundcubemail 搭建邮件服务器管理系统(四)

实现 SMTP 发信认证

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:[email protected]                           // 指定发件人地址
250 2.1.0 Ok
RCPT TO:[email protected]                                   //  指定收件人地址
454 4.7.1 : Relay access denied 
                                                                        //  发送外域的发信请求被拒绝
quit                                                                //  断开telnet连接
221 2.0.0 Bye
Connection closed by foreign host.
  • 为用户user01为例,生成用户名、密码的加密字串
[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:[email protected]                    //指定发件人地址
250 2.1.0 Ok
RCPT TO:[email protected]                   //指定收件人地址
250 2.1.5 Ok
DATA                                       //开始编写邮件内容
354 End data with .
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.

你可能感兴趣的:(运维工程师,JAVA工程师)