1、停用sendmail和postfix
systemctl stop sendmail
systemctl disable sendmail
systemctl stop postfix
systemctl disbale postfix
2、安裝mailx
yum -y install mailx
3、配置mail.rc,填寫163相關信息,這裏賬號信息配置省略,密碼填寫的是客戶端的授權碼
vim /etc/mail.rc
切換到最後一行,填寫賬號服務器等相關信息
set from=你自己的郵箱地址@163.com
set smtp=smtp.163.com
set smtp-auth-user=你自己的郵箱地址@163.com
set smtp-auth-password=你自己163客戶端授權密碼,不是你郵箱登陸密碼噢
set smtp-auth=login
4、發送測試郵件
echo "mail test" | mailx -s "mail alert" [email protected]
echo "mail test" //指的是郵件內容
mailx -s "mail alert" //指的是郵件的標題
[email protected] //指的是收件人
5、郵箱可以接收到
以上是基於25號端口,如果你是本地或者內網服務器,那麼郵件應該是可以正常接受的,但如果你用的是阿里、騰訊或者其他雲服務器,他們默認把25端口封掉,所以此方法使用如下配置
如果是阿里雲等服務器,由於屏蔽了25號端口,會導致連接超時,所以我們需要配置465端口,配置如下
1、自己創建ssl證書
mkdir -p /root/.certs/
echo -n | openssl s_client -connect smtp.163.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/qq.crt //如果是126或者qq郵箱,把smtp.163.com:465中的163改掉即可
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
2、證書配置好後,更改一下mailx配置文件
set from=你自己的郵箱地址@163.com
set smtp=smtp.163.com
set smtp-auth-user=你自己的郵箱地址@163.com
set smtp-auth-password=你自己163客戶端授權密碼,不是你郵箱登陸密碼噢
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/root/.certs
3、登陸到雲服務器中,發送測試郵件,應該是可以正常接收
echo "mail test" | mailx -s "mail alert" [email protected]
4、以上是基於本地和雲服務器配置mailx郵件發送的所有配置
5、如果你用的是雲服務器,並且使用了mailx作爲zabbix告警媒介,如果zabbix不能通過mailx正常告警,但你又堅信自己zabbix配置沒問題,那接受不到郵件應該是mailx的問題,修改一下mailx的配置
配置文件中的
set nss-config-dir=/root/.certs
改成set nss-config-dir=/etc/pki/nssdb
最終配置如下圖
set from=你自己的郵箱地址@163.com
set smtp=smtp.163.com
set smtp-auth-user=你自己的郵箱地址@163.com
set smtp-auth-password=你自己163客戶端授權密碼,不是你郵箱登陸密碼噢
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/etc/pki/nssdb
以上是mailx的全部配置,希望能夠幫到有需求的朋友們,歡迎各位留言討論,我的QQ聯繫方式:87214961