CentOS使用Mail进行告警邮件发送
1、检查mail是否安装,如果没有则可以通过yum安装
yum -y install mailx
2、修改/etc/mail.rc,添加如下配置:
vim /etc/mail.rc
# mail config
set from=***********@163.com
set smtp=smtps://smtp.163.com:465
set smtp-auth-user=********@163.com
set smtp-auth-password=*********
set smtp-auth=login
set nss-config-dir=/root/.certs
set ssl-verify=ignore
---说明
from:对方收到邮件时显示的发件人
smtp:指定第三方发邮件的smtp服务器地址
set smtp-auth-user:第三方发邮件的用户名
set smtp-auth-password:邮箱授权码
smtp-auth:SMTP的认证方式,默认是login,也可以改成CRAM-MD5或PLAIN方式
nss-config-dir: SSL验证信息存放位置,需要后面步骤创建
ssl-verify: SSL验证信息忽略
3、创建 /root/.certs 目录
mkdir -p /root/.certs
4、下载证书到 /root/.certs 目录,本例是下载163证书
a、向163请求证书
echo -n | openssl s_client -connect smtp.163.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/163.crt
b、添加一个证书到本地:
certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt
c、再次添加一个证书到本地:
certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt
d、标记证书被信任
cd /root/.certs/
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i 163.crt
5、测试邮件发送,有两种方式,可以用mail命令也可以用mailx命令,如下:
使用mail命令 ,加上 -v 会显示发送过程,多个接收人直接在后面空格加上其他人邮箱地址:
echo "hallo" | mail -v -s "this is Test Mail" -a /home/123.txt xxxxxx@qq.com bbbbbb@qq.com
-s <邮件主题>:指定邮件的主题;
-c <地址>:添加邮件抄送人,多个人时用逗号隔开;
-b <地址>:添加邮件暗送人;
-a <附件>: 添加附件.
征途漫漫,惟有奋斗!

浙公网安备 33010602011771号