一、關閉其他的郵件工具
發送的郵件用到mailx就可以了,其他可以關閉。CentOS6.8默認安裝的是postfix。
chkconfig postfix off #關閉開機啟動
service postfix stop #關閉服務運行
chkconfig sendmail off
service sendmail stop
二、安裝mailx
沒什么特殊要求就yum安裝直接
yum -y install mailx
三、配置mail.rc文件
首先要保證你的qq郵箱開啟了SMTP服務
vim /etc/mail.rc
set from=XXXXXXXX@qq.com #你的qq郵箱
set smtp=smtps://smtp.qq.com:465 #郵箱所在服務器和端口地址
set smtp-auth-user=XXXXXXXXX@qq.com #你的qq郵箱
set smtp-auth-password=aaaaabbbbbccccc #這部分要划下重點,這里是配置授權碼,而不是郵箱的獨立密碼,否則發送郵件時報錯(smtp-server: 535 Error: Ȩ¼http://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256)
set smtp-auth=login #默認login即可
set ssl-verify=ignore #ssl認證方式
set nss-config-dir=/root/.certs #證書所在目錄,這個可以自定義目錄所在位置
四、請求數字證書
mkdir
-p
/root/
.certs/
echo
-n | openssl s_client -connect smtp.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
cd /root/.certs/
certutil -A -n
"GeoTrust SSL CA - G3"
-t
"Pu,Pu,Pu"
-d ~/.certs/./ -i qq.crt
certutil -L -d
/root/
.certs
五、發送測試郵件
echo
"郵件正文"
| mail -s
"郵件主題"
xxx@163.com
發送文件的另外幾種格式
其他郵件發送格式
cat
file.txt
| mail -s
"郵件主題"
xxx@163.com
mail -s
"郵件主題"
xxx@163.com <
file
.txt
打開你的163郵箱如果收到此qq郵箱發來的測試郵件即為配置成功