1.安装mailx
1 |
yum install mailx -y |
2.修改配置文件/etc/mail.rc,可以使用外部SMTP服务器
1 2 3 4 5 6 7 |
set from=xxxooo@aliyun.com set smtp=smtps://smtp.mxhichina.com:465 set smtp-auth-user=xxxooo@aliyun.com set smtp-auth-password=你的密码 set smtp-auth=login set ssl-verify=ignore set nss-config-dir=/root/.certs #/etc/pki/nssdb/ |
3、证书配置
1 2 3 4 5 |
mkdir -p /root/.certs/ echo -n | openssl s_client -connect smtp.mxhichina.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/mxhichina.crt certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/mxhichina.crt certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/mxhichina.crt certutil -L -d /root/.certs |
进入存放证书的目录,执行
1 2 |
cd /root/.certs certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i mxhichina.crt |
4、使用三种方式发送邮件
命令行: mail -s “theme” addressee,回车后输入内容按Ctrl+D发送邮件.
管道符: echo “mail main content” | mail -s “theme” addressee
文件内容作为邮件内容: mail -s “theme” addressee < /tmp/t.txt