linux下使用mail命令發送郵件


安裝:

$ yum install mailx

配置:

$ vim /etc/mailx    #在結尾追加配置
set from=example@163.com    #發送服務器
set smtp=smtps://smtp.163.com:465  #smtp服務器地址,如果不使用ssl方式,可寫成:set smtp=smtp.qq.com:25                               
set smtp-auth-user=example@163.com  #發送者郵件名稱
set smtp-auth-password=************** #密碼,非郵箱登陸密碼
set smtp-auth=login   #發送郵件時的登陸方式
set ssl-verify=ignore #啟用ssl,如果不使用ssl,則注釋當前及最后一行配置即可
set nss-config-dir=/root/.certs  #證書配置路徑,普通用戶需要有訪問權限才能發送郵件

配置ssl證書:

$ mkdir -p /root/.certs/
$ echo -n | openssl s_client -connect smtp.163.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/163.crt
$ certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt
$ certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt
$ certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ~/.certs/./ -i ~/.certs/163.crt
$ certutil -L -d /root/.certs

測試效果:

$ echo "正文" | mail -s '標題' example@163.com


免責聲明!

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



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