1.首先stop sendmail和postfix
system status sendmail
system stop sendmail
system status postfix.service
system stop postfix.service
2.安装mail
yum install mailx -y
3.编辑配置文件
vim /etc/mail.rc
在最后添加下面内容
set from=xxxxx@126.com #发送服务器
set smtp=smtps://smtp.126.com:465 #smtp服务器地址,如果不使用ssl方式,可写成:set smtp=smtp.126.com:25
set smtp-auth-user=xxxxxx@126.com #发送者邮件名称
set smtp-auth-password=xxxxx #密码,非邮箱登陆密码
set smtp-auth=login #发送邮件时的登陆方式
set ssl-verify=ignore #启用ssl,如果不使用ssl,则注释当前及最后一行配置即可
set nss-config-dir=/root/.certs #证书配置路径,普通用户需要有访问权限才能发送邮件
如果报错
[root@localhost .certs]# Error in certificate: Peer’s certificate issuer is not recognized.
smtp-server: 535 Error: authentication failed
“/root/dead.letter” 11/307
. . . message not sent.

则需配置ssl证书
mkdir -p /root/.certs/
cd /root/.certs/
[root@server .certs]# echo -n | openssl s_client -connect smtp.126.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/126.crt
[root@server .certs]# certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/126.crt
[root@server .certs]# certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/126.crt
[root@server .certs]# certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ~/.certs/./ -i ~/.certs/126.crt
[root@server .certs]# certutil -L -d /root/.certs
最后测试一下,嘻嘻
echo "zabbix test" |mailx -v -s "zabbix alert" xxxxxx@126.com
本文介绍了如何在Linux系统中停止sendmail和postfix服务,安装并配置mail命令,以及如何处理发送邮件时遇到的SSL证书错误。在遇到错误如'Error in certificate: Peer’s certificate issuer is not recognized.'和'535 Error: authentication failed'时,文章提供了配置SSL证书的解决方案,并在最后进行了测试验证。

1108

被折叠的 条评论
为什么被折叠?



