美文网首页
Shell发送QQ邮件

Shell发送QQ邮件

作者: 喵星人ZC | 来源:发表于2019-04-16 20:43 被阅读0次

    一、开启QQ邮件四个服务,生成授权码(设置-->账户)


    image.png

    二、服务器邮件配置
    1、关闭sendmail服务

    #sendmial
    service sendmail stop
    chkconfig sendmail off
    

    2、启动postfix 服务

    [hadoop@hadoop000 ~]$ service postfix status
    --------------------------------------------------------------------
    [root@hadoop000 ~]# service postfix status
    master (pid  2274) is running...
    --------------------------------------------------------------------
    [root@hadoop000 ~]# chkconfig postfix on
    

    如果postfix start失败报以下错误,请执行

    [root@rzdatahadoop002 ~]# postfix check
    postfix: error while loading shared libraries: libmysqlclient.so.16: cannot open shared object file: No such file or directory
    --------------------------------------------------------------------
    [root@rzdatahadoop002 ~]# rpm -qa|grep mysql
    --------------------------------------------------------------------
    [root@rzdatahadoop002 ~]# yum install mysql-libs
    

    3、创建认证

    [root@hadoop000 ~]# mkdir -p /root/.certs/
    --------------------------------------------------------------------
    [root@hadoop000 ~]# echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/qq.crt
    depth=2 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = DigiCert Global Root CA
    verify return:1
    depth=1 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = GeoTrust RSA CA 2018
    verify return:1
    depth=0 C = CN, ST = Guangdong, L = Shenzhen, O = Tencent Technology (Shenzhen) Company Limited, OU = R&D, CN = pop.qq.com
    verify return:1
    DONE
    --------------------------------------------------------------------
    [root@hadoop000 ~]# certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
    --------------------------------------------------------------------
    [root@hadoop000 ~]# certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
    --------------------------------------------------------------------
    [root@hadoop000 ~]# certutil -L -d /root/.certs
    
    Certificate Nickname                                         Trust Attributes
                                                                 SSL,S/MIME,JAR/XPI
    
    GeoTrust SSL CA                                              C,,  
    --------------------------------------------------------------------
    [root@hadoop000 ~]# cd /root/.certs
    --------------------------------------------------------------------
    [root@hadoop000 .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.
    --------------------------------------------------------------------
    [root@hadoop000 .certs]# ll
    total 80
    -rw------- 1 root root 65536 Apr 16 20:04 cert8.db
    -rw------- 1 root root 16384 Apr 16 20:04 key3.db
    -rw-r--r-- 1 root root  2529 Apr 16 20:04 qq.crt
    -rw------- 1 root root 16384 Apr 16 20:04 secmod.db
    

    4、配置mail.rc(改为自己的邮箱)

    set from=123456789@qq.com
    set smtp=smtp.qq.com
    set smtp-auth-user=123456789
    
    #授权码(第一步生成的)
    set smtp-auth-password=vszvqerunewxbgcg
    set smtp-auth=login
    set smtp-use-starttls
    set ssl-verify=ignore
    set nss-config-dir=/root/.certs
    

    三、测试
    1、发送hello word到邮箱

    [root@hadoop000 .certs]# echo  "hello word" | mail -s "title" 123456789@qq.com 
    

    四、封装脚本

    1、发送纯文本信息邮件

    #!/bin/bash 
    
    JOB_NAME="Spark ETL"
    FROM_EMAIL="123456789@qq.com"
    TO_EMAIL="123456789@qq.com"
    
    RUNNINGNUM=1
    
    echo -e "`date "+%Y-%m-%d %H:%M:%S"` : The current running $JOB_NAME job num is $RUNNINGNUM in `hostname -i` ......" | mail \
    -r "From: alertAdmin <${FROM_EMAIL}>" \
    -s "Warn: Skip the new $JOB_NAME spark job." ${TO_EMAIL}
    
    image.png

    2、发送带有附件的邮箱

    [root@hadoop000 soul]# touch sparketl.log
    [root@hadoop000 soul]# echo "aaa" >> sparketl.log
    ---------------------------------------------------------------------
    [root@hadoop000 soul]# cat mail_attachment.sh 
    #!/bin/bash 
    
    
    FROM_EMAIL="462292793@qq.com"
    TO_EMAIL="462292793@qq.com"
    
    LOG=/root/soul/sparketl.log 
    
    
    echo -e "`date "+%Y-%m-%d %H:%M:%S"` : Please to check the fail log attachement." | mailx \
    -r "From: alertAdmin <${FROM_EMAIL}>" \
    -a ${LOG} \
    -s "Critical:Spark ETL  fail log." ${TO_EMAIL}
    -------------------------------------------------------------------------
    [root@hadoop000 soul]# sh mail_attachment.sh 
    
    image.png

    相关文章

      网友评论

          本文标题:Shell发送QQ邮件

          本文链接:https://www.haomeiwen.com/subject/douiwqtx.html