centos下利用mail命令進行郵件發送


centos下默認自帶mail命令:

可以用如下命令查看存放位置:

which mail

結果如下:

 

如果沒有安裝可以使用 如下命令安裝 

yum -y install mailx

利用mail命令進行郵件發送,需要利用到第三方郵件服務器,如163等,需要一個授權碼來識別(注意不是郵箱密碼),獲取授權碼過程如下:

需要手機號驗證開啟,具體過程可以百度 163郵箱授權

參考: https://jingyan.baidu.com/article/aa6a2c149f7b250d4c19c4b3.html

授權碼獲取到后,按如下步驟配置

1、修改/etc/mail.rc

vim /etc/mail.rc

2、在最后添加如下配置:

# mail config
set from=***********@163.com  
set smtp=smtps://smtp.163.com:465  
set smtp-auth-user=********@163.com
set smtp-auth-password=********* 
set smtp-auth=login 
set nss-config-dir=/root/.certs  
set ssl-verify=ignore 

---說明
from:對方收到郵件時顯示的發件人
smtp:指定第三方發郵件的smtp服務器地址
set smtp-auth-user:第三方發郵件的用戶名
set smtp-auth-password:郵箱授權碼
smtp-auth:SMTP的認證方式,默認是login,也可以改成CRAM-MD5或PLAIN方式
nss-config-dir: SSL驗證信息存放位置,需要后面步驟創建
ssl-verify: SSL驗證信息忽略

3、創建 /root/.certs 目錄

mkdir -p /root/.certs

4、下載證書到 /root/.certs 目錄,本例是下載163證書

      a、向163請求證書

echo -n | openssl s_client -connect smtp.163.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/163.crt

     b、添加一個證書到本地:

certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt

     c、再次添加一個證書到本地:

certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt

     d、標記證書被信任

cd /root/.certs/
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i 163.crt 

5、測試郵件發送,有兩種方式,可以用mail命令也可以用mailx命令,如下:

a、使用mail命令 ,加上 -v 會顯示發送過程,多個接收人直接在后面空格加上其他人郵箱地址:

echo "hallo" | mail -v -s "this is Test Mail" xxxxxx@qq.com bbbbbb@qq.com

b、使用mailx命令:

mailx -s "hello" xxxxxx@qq.com

回車后手動輸入郵件正文,如下:

然后按ctrl+d結束輸入,自動發送

 參考:

https://blog.xunxe.com/1579.html

http://blog.51cto.com/12832314/2125950


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM