#1 安装mailx yum -y install sendmail mailx libreport-plugin-mailx sharutils mutt #2 修改配置文件/etc/mail.rc,最后添加以下几行 # set sendmail set from=abc@xxx.com set smtp=smtps://smtp.exmail.qq.com:465 set smtp-auth-user=abc@xxx.com set smtp-auth-password=xxx set smtp-auth=login set nss-config-dir=/etc/pki/nssdb/ set ssl-verify=ignore #3 设置证书 cd /etc/pki/nssdb #获取证书文件 echo -n | openssl s_client -connect smtp.exmail.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ./qq.crt #添加证书到证书数据库中 certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt #4 测试邮件发送 echo "Hello World" |mail -s test xxx@xxx.com #-s :指定发送邮件的主题 #将以"hello world"为内容,test为主题的邮件,发送给xxx@xxx.com #5 添加附件测试 echo "Hello World" |mail -s test -a /etc/fujian.txt allenwu@hinabian.com #将以"hello world"为内容,test为主题,/etc/fujian.txt为附件的邮件,发送给xxx@xxx.com #6 将文件内容,作为邮件内容发送给指定邮箱 mail -s test -a /etc/fujian.txt allenwu@hinabian.com </etc/passwd