1.查看是否已安裝郵件服務 rpm -qa|grep mail
2. 如果沒有mailx,則安裝
yum install -y mailx
3.配置 cat /etc/mail.rc
set [email protected]
set smtp=smtp.qq.com
set [email protected]
set smtp-auth-password=xxxx
set smtp-auth=login
如圖:
注:smtp-auth-password 是授權密碼,不是郵箱密碼。設置如下圖,qq郵箱賬戶設置,生成授權碼,然後設置smtp-auth-password
4.發送郵件
mailx -s "centos7測試郵件" [email protected] < ~/test.txt
echo 'hello' | mail -s "Linux測試" [email protected]
cat ~/test.txt | mail -s "郵件測試" [email protected]