获取授权码
1.邮箱点击设置-账户
2.开启POP3/SMTP 、IMAP/SMTP 并点击生成授权码
启动postfix
service postfix start
如果postfix start失败
[root@hadoop001 ~]# postfix check
postfix: error while loading shared libraries: libmysqlclient.so.16: cannot open shared object file: No such file or directory
[root@hadoop001 ~]# rpm -qa|grep mysql
[root@hadoop001 ~]# yum install mysql-libs
创建认证
mkdir -p /root/.certs/
echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne ‘/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p’ > ~/.certs/qq.crt
certutil -A -n “GeoTrust SSL CA” -t “C,” -d ~/.certs -i ~/.certs/qq.crt
certutil -A -n “GeoTrust Global CA” -t “C,” -d ~/.certs -i ~/.certs/qq.crt
certutil -L -d /root/.certs
cd /root/.certs
certutil -A -n “GeoTrust SSL CA - G3” -t “Pu,Pu,Pu” -d ./ -i qq.crt
配置mail.rc
vi /etc/mail.rc
set from=XXX@qq.com
set smtp=smtp.qq.com
set smtp-auth-user=XXX@qq.com
#授权码
set smtp-auth-password=dqiqzlqpslvxdieb
set smtp-auth=login
set smtp-use-starttls
set ssl-verify=ignore
set nss-config-dir=/root/.certs
测试
echo “hello word” | mail -s “title” XX@qq.com
发邮件不带附件 sh
#!/bin/bash
JOB_NAME=“TEST”
FROM_EMAIL="XXX@qq.com"
TO_EMAIL="XXX@qq.com"
RUNNINGNUM=1
echo -e "date "+%Y-%m-%d %H:%M:%S"
: The current running $JOB_NAME job num is KaTeX parse error: Expected 'EOF', got '\ ' at position 34: …......" | mail \̲ ̲-r "From: alert…{FROM_EMAIL}>"
-s “Warn: Skip the new $JOB_NAME spark job.” ${TO_EMAIL}
发邮件不带附件 sh
#!/bin/bash
FROM_EMAIL="XXX@qq.com"
TO_EMAIL="XXX@qq.com"
LOG=/root/shell/ruozedata.log
echo -e "date "+%Y-%m-%d %H:%M:%S"
: Please to check the fail sql attachement." | mailx
-r “From: alertAdmin <${FROM_EMAIL}>”
-a ${LOG}
-s “Critical:DSHS fail sql.” ${TO_EMAIL}