解决mailx发邮件报错:esmtp-server: 504 5.7.4 Unrecognized authentication type [HK2PR02CA0167.apcprd02.prod.outlook.com] "/root/dead.letter" 11/302 . . . message not sent.

时间:2023-03-09 07:07:00
解决mailx发邮件报错:esmtp-server: 504 5.7.4 Unrecognized authentication type [HK2PR02CA0167.apcprd02.prod.outlook.com] "/root/dead.letter" 11/302 . . . message not sent.

报错信息:

esmtp-server: 504 5.7.4 Unrecognized authentication type [HK2PR02CA0167.apcprd02.prod.outlook.com]
"/root/dead.letter" 11/302
. . . message not sent.

背景:

由遇到的以上问题可知阿里云服务器关闭了25端口,发送邮件才会显示链接超时,而且官方不允许打开该端口,而且大部分邮件都是通过25端口
详细的可以查看:常见邮箱端口

解决mailx发邮件报错:esmtp-server: 504 5.7.4 Unrecognized authentication type [HK2PR02CA0167.apcprd02.prod.outlook.com] "/root/dead.letter" 11/302 . . . message not sent.

所以除了换邮箱之外(端口不是25的,要么是国外不好申请,要么收费,我们摸摸口袋…)
言归正传,我们以网易163邮箱为例,使用SSL下的465端口。

解决mailx发邮件报错:esmtp-server: 504 5.7.4 Unrecognized authentication type [HK2PR02CA0167.apcprd02.prod.outlook.com] "/root/dead.letter" 11/302 . . . message not sent.

解决mailx发邮件报错:esmtp-server: 504 5.7.4 Unrecognized authentication type [HK2PR02CA0167.apcprd02.prod.outlook.com] "/root/dead.letter" 11/302 . . . message not sent.

 解决方式:

  一、请求数字证书:

[root@zabbix-server-center ~]# mkdir -p /root/.certs/    ###创建目录,用来存放证书
[root@zabbix-server-center ~]# echo -n | openssl s_client -connect smtp.163.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/163.crt
[root@zabbix-server-center ~]# certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt ###添加一个ssl证书到证书数据库中
[root@zabbix-server-center ~]# certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt ###添加一个Global证书到证书数据库中
[root@zabbix-server-center ~]# certutil -L -d /root/.certs ###列出目录下的数字证书

  二、配置发件人:

[root@zabbix-server-center ~]# vim /etc/mail.rc

  在配置文件中添加如下内容:

set from=AAA@163.com
set smtp=smtps://smtp.163.com:465
set smtp-auth-user=AAA@163.com
set smtp-auth-password=***** ###该密码是在网易邮箱中申请的第三方客户端密码,不是账户的登陆密码。
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/root/.certs

  进入设置,找到POP3/SMTP/IMAP项,将其开启,随后会得到一个“邮箱客户端授权码”,也就是:set smtp-auth-password=邮箱客户端授权码。

解决mailx发邮件报错:esmtp-server: 504 5.7.4 Unrecognized authentication type [HK2PR02CA0167.apcprd02.prod.outlook.com] "/root/dead.letter" 11/302 . . . message not sent.

  三、邮箱测试:

    注意有些邮箱账号必须要写全,否则收不到邮件!例如:live邮箱就必须写全才能收到邮件。但是163邮箱不用写全,就能接收到邮件。echo "hi jack,i am rose" | mail -s "zabbix"   xxx@163.com

[root@zabbix-server-center .certs]# echo "hi jack,i am rose" | mail -s "zabbix" www.xxx@live.com

 解决mailx发邮件报错:esmtp-server: 504 5.7.4 Unrecognized authentication type [HK2PR02CA0167.apcprd02.prod.outlook.com] "/root/dead.letter" 11/302 . . . message not sent.

   四、解决证书不被信任问题:

解决mailx发邮件报错:esmtp-server: 504 5.7.4 Unrecognized authentication type [HK2PR02CA0167.apcprd02.prod.outlook.com] "/root/dead.letter" 11/302 . . . message not sent.

  依次输入命令:

[root@zabbix-server-center ~]# cd /root/.certs/
[root@zabbix-server-center .certs]# ll
[root@zabbix-server-center .certs]# certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i 163.crt

  解决问题,成功的标志:

Notice: Trust flag u is set automatically if the private key is present.

解决mailx发邮件报错:esmtp-server: 504 5.7.4 Unrecognized authentication type [HK2PR02CA0167.apcprd02.prod.outlook.com] "/root/dead.letter" 11/302 . . . message not sent.