Shell发送邮件

打开QQ邮箱,生成权限码

服务器配置

#下载mailx服务
[root@localhost shell]# yum -y install mailx
#开启postfix功能
[root@localhost shell]# systemctl start postfix
[root@localhost shell]# systemctl status postfix

● postfix.service - Postfix Mail Transport Agent
   Loaded: loaded (/usr/lib/systemd/system/postfix.service; disabled; vendor preset: disabled)
   Active: active (running) since 五 2020-10-23 01:01:12 CST; 8h ago
  .............

#创建证书(直接复制粘贴)
[root@localhost shell]# mkdir -p /root/.certs
[root@localhost shell]# echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/qq.crt
................
depth=2 C = BE, O = GlobalSign nv-sa, OU = Root CA, CN = GlobalSign Root CA
verify return:1
depth=1 C = BE, O = GlobalSign nv-sa, CN = GlobalSign Organization Validation CA - SHA256 - G2
verify return:1
depth=0 C = CN, ST = guangdong, L = shenzhen, O = Shenzhen Tencent Computer Systems Company Limited, CN = *.mail.qq.com
verify return:1
DONE
..............
[root@localhost .certs]# certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
[root@localhost .certs]# certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
[root@localhost .certs]# certutil -L -d ~/.certs
.............
Certificate Nickname                                         Trust Attributes
                                                             SSL,S/MIME,JAR/XPI

GeoTrust SSL CA                                              C,,
..............
[root@localhost .certs]# certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt
Notice: Trust flag u is set automatically if the private key is present.

#修改mail配置文件
[root@localhost .certs]# vim /etc/mail.rc
..........
set from=12xxxxx@qq.com
set smtp=smtp.qq.com
set smtp-auth-user=12xxxx
#授权码
set smtp-auth-password=权限码
set smtp-auth=login
set smtp-use-starttls
set ssl-verify=ignore
set nss-config-dir=/root/.certs

测试

#同步服务器时间,成功5次发送邮件,并附带log附件
[root@localhost shell]# cat ntp.sh 
#!/bin/env bash
NTP=ntp1.aliyun.com
dir_log=/opt/ntp.log
count=0
while true
do
  ntpdate $NTP >> /opt/ntp.log
  if [ $? -ne 0 ];then
    echo "同步失败"| mail -s "checkTime" root@localhost
  else
     count=$[$count+1]
     if [ $count -eq 5 ];then
         echo "同步5次"| mail -s "checkTime" -a $dir_log  1255109811@qq.com
         count=0;
     fi
  fi
  sleep 3
done

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值