Linux Centos7傳送QQ郵件

春日宴發表於2021-02-13

一、關閉本機的sendmail服務或者postfix服務

#sendmial
service sendmail stop
chkconfig sendmail off

#postfix
service postfix stop
chkconfig postfix off

二、安裝mailx

yum -y install mailx
ln -s /bin/mailx /bin/mail
chown -R zabbix.zabbix /bin/mail

三、安裝證書

mkdir -p /etc/pki/nssdb/
cd /etc/pki/nssdb

echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /etc/pki/nssdb/qq.crt 
 
certutil -A -n "GeoTrust SSL CA" -t "C,," -d /etc/pki/nssdb/ -i /etc/pki/nssdb/qq.crt  
certutil -A -n "GeoTrust Global CA" -t "C,," -d /etc/pki/nssdb/ -i /etc/pki/nssdb/qq.crt  
certutil -L -d /etc/pki/nssdb/ 
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu"  -d ./ -i qq.crt 

四、配置郵件

(1)獲取授權碼




安裝步驟操作,傳送完郵件會生成一個授權碼,複製儲存稍後使用

(2)配置郵件資訊

vim /etc/mail.rc

在文字最後插入

set nss-config-dir=/etc/pki/nssdb/
set smtp-user-starttls
set ssl-verify=ignore
 
set from=123456@qq.com #使用自己的QQ郵箱,這個是發件箱
set smtp=smtps://smtp.qq.com:465
set smtp-auth-user=123456@qq.com #外部smtp伺服器認證的使用者名稱,也是QQ郵箱
set smtp-auth-password=授權碼
set smtp-auth=login

五、測試

echo  test | mail -v -s " test"  test@qq.com  #此郵箱為收件箱,使用其他郵箱作為收件箱

測試成功

測試失敗(這是多半是證書問題)

參考資料

Linux 使用命令傳送郵件
Linux CentOS7 Zabbix郵件報警 通過QQ企業郵箱傳送郵件的問題解決方案

相關文章