linux 发送邮件设置

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/likaiasddsa/article/details/89764412

获取授权码

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 [email protected]
set smtp=smtp.qq.com
set [email protected]
#授权码
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” [email protected]
在这里插入图片描述

发邮件不带附件 sh

#!/bin/bash
JOB_NAME=“TEST”
FROM_EMAIL="[email protected]"
TO_EMAIL="[email protected]"
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="[email protected]"
TO_EMAIL="[email protected]"
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}

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/likaiasddsa/article/details/89764412