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]