linux使用mail发送邮件

本文介绍了如何在Linux系统中停止sendmail和postfix服务,安装并配置mail命令,以及如何处理发送邮件时遇到的SSL证书错误。在遇到错误如'Error in certificate: Peer’s certificate issuer is not recognized.'和'535 Error: authentication failed'时,文章提供了配置SSL证书的解决方案,并在最后进行了测试验证。

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值