此方法可用在RedHat  6 、7、8

yum install mailx sendmail

#配置账号,mailtest

cp /etc/mail.rc

#

account 发送邮箱账号 {

set smtp=邮件服务器地址

set from=发件人信息

set smtp-auth-user=发件人账号

set smtp-auth-password=发件人密码

set smtp-auth=login

}

#最底部添加


account mailtest  {

set smtp=mail.xxx.com

set from=notice@xxx.com

set smtp-auth-user=notice@xxx.com

set smtp-auth-password=密码

set smtp-auth=login

}

测试邮件echo 邮件内容|mail -A 发送账号mailtest -s主题mail test  收件人地址多人用,分开

echo "mail test 20230809"|mail -A mailtest -s 'mail test' changhe@xxx.com