1.安装mailx邮件服务
yum -y install mailx
若有其他邮件服务器建议先停止常见如下
service sendmail stop
chkconfig sendmail off
service postfix stop
chkconfig postfix off
2.配置邮件服务
vim /etc/mail.rc
set from=xxxxx@aliyun.com # 公司授权个人的阿里企业邮箱 set smtp=smtps://smtp.exmail.qq.com:465 #设置smtp服务器 set smtp-auth-user=xxxxx@aliyun.com # 公司授权个人的阿里企业邮箱 set smtp-auth-password=xxxxx # 企业邮箱密码 set smtp-auth=login set ssl-verify=ignore set nss-config-dir=/etc/mail/scripts/.certs #证书所在目录
因为阿里云 ECS 封禁了 25 端口,所以我们只能使用 TLS 方式(TSL 也就是使用 SSL 加密的方式,使用 465 或者其他端口来发送邮件)绕过 25 端口需求来发送邮件,
所以必须先获得邮箱的 SSL 证书并存放到本地,最后一行的 nss-config-dir 就是制定的存放 QQ 邮箱 SSL 证书的位置。在末尾添加以下内容(或直备份源文件后直接更改源文件)
3.配置 腾讯企业邮箱的 SSL 证书
mkdir -p /etc/mail/scripts/.certs echo -n | openssl s_client -connect smtp.exmail.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /etc/mail/scripts/.certs/qq.crt certutil -A -n "GeoTrust SSL CA" -t "C,," -d /etc/mail/scripts/.certs -i /etc/mail/scripts/.certs/qq.crt certutil -A -n "GeoTrust Global CA" -t "C,," -d /etc/mail/scripts/.certs -i /etc/mail/scripts/.certs/qq.crt certutil -L -d /etc/mail/scripts/.certs/ cd /etc/mail/scripts/.certs/ && certutil -A -n "GeoTrust SSL CA – G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt
4.为了防止出现前文所说的发送邮件警告提示,还需要进入邮箱 SSL 证书存放目录 /etc/mail/scripts/.certs 里执行如下命令:
cd /etc/mail/scripts/.certs/ && certutil -A -n "GeoTrust SSL CA – G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt
5.出现以下提示则为成功
**Notice: Trust flag u is set automatically if the private key is present.**
6.测试企业邮箱发送邮件
mailx -s "测试标题" aa@aliyun.com < 1.txt #单个收件人
mailx -s "测试标题" aa@aliyun.com bb@aliyun.com < 1.txt #多个收件人
注意事项#企业邮箱需要关闭安全登录
本文参考以下博客
https://blog.csdn.net/ljj_18539663587/article/details/104821751
https://blog.csdn.net/lazyRabbitLLL/article/details/79718450
https://blog.espnlol.com/?p=335