安裝app
#mailxyum install mailx -yide
編輯 /etc/mail.rc 文件內容,追加如下內容(請替換其中的登陸用戶和密碼值): 測試
set from=xx@xxx.comspa
set smtp="smtps://smtp.exmail.qq.com:465" #這是重點命令行
set smtp-auth-user="xx@xxx.com"orm
set smtp-auth-password="xxxx"blog
set smtp-auth=loginip
set ssl-verify=ignoressl
set nss-config-dir=/etc/pki/nssdb ci
配置證書(注意:上面配置的nss-config-dir就是存放證書的路徑,可自定義
發送測試郵件
# echo "測試郵件"|mailx -v -s "標題" 123@456.com
四、使用mailx發送郵件
-s subject 郵件標題
-a file 添加附件
-v 顯示郵件發送詳細過程
-V 顯示mail(mailx)版本信息
郵件內容可來源於管道、輸入重定向等,例如:
mailx -s "發件人名稱 郵件標題" mailname@163.com < message.txt
cat message | mailx -s "發件人名稱 郵件標題" mailname@163.com
echo "mail test message" | mailx -v -s " title" mailnamexxx3@163.com
也能夠直接從命令行輸入郵件內容:
mailx -s "發件人名稱 郵件標題" mailname@163.com ##輸入完後回車按Ctrl+D提交發送
多個收件人之間用逗號分隔:
cat message | mailx -s "發件人名稱 郵件標題" mail1@163.com, mail2@163.com, mail3@163.com
一個問題:
使用上面的配置,郵件是徹底可以發出去的,可是發送郵件的時候會提示 「Error in certificate: Peer’s certificate issuer is not recognized.」提示,運行如下命令生成一個證書便可。
# mkdir -p /root/.certs/
# cd /root/.certs/
獲取證書:
# echo -n | openssl s_client -connect smtp.exmail.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
修改配置
set nss-config-dir=/root/.certs
注意 :配置了證書沒起效