一、centos7系统默认自带了mail邮件系统,需要配置自己的qq邮件服务器

开启qq邮件服务器:

image.png

二、生成证书

mkdir -p  /root/.certs   创建证书目录
echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/qq.crt     #获取邮件服务器证书
chmod +x /root/.certs/qq.crt       #qq.crt 添加执行权限
certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt     #添加SSL证书到数据库
certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt        #添加global证书到数据库
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ~/.certs -i ~/.certs/qq.crt  #指定受信任证书,防报错
certutil -L -d /root/.certs  #列出安全数据库中的证书

三、修改mail配置文件
vi /etc/mail.rc 在文件末尾添加邮件服务器信息
image.png

set from=768429319@qq.com
set smtp=smtps://smtp.qq.com:465
set smtp-auth-user=768429319@qq.com
set smtp-auth-password=你的授权码
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/root/.certs

mail -s "your subject" 469688010@qq.com

四、最后的脚本文件:

#! /bin/bash

to="dec@**.org.cn andy@**.org.cn"
from="768429319@qq.com"
subject="告警提醒:短链接系统发生异常"
body="短链接系统发生异常,正在处理中"
cd /home/ohUrlShortener-main/docker/
if [ $(docker ps | grep ohurlshortener* | grep Up | wc -l) == "4" ];then
    echo "service is ok"
else
    echo "${body}" | mail -s "${subject}" -r "${from}" "${to}"
    # 容器销毁
    echo "stop ohurlshortenner container begin"
    sh /home/ohUrlShortener-main/docker/stop_destory.sh
    echo "stop ohurlshortenner container over"
    #同步执行
    wait
    # 容器启动
    echo "start ohurlshortenner container begin" 
    sh /home/ohUrlShortener-main/docker/one_step_start.sh
    echo "start ohurlshortenner container over"
fi

参考:https://blog.csdn.net/ayychiguoguo/article/details/120849766


兰亭
3 声望0 粉丝

认识的人越多,我就越喜欢狗


« 上一篇
js transform案例

引用和评论

0 条评论