参考连接html
使用阿里云ECS的站长们应该都知道阿里云ECS为了防止其服务器被当作垃圾邮件发送服务器禁止了邮件端口25的使用,这就形成系统级的提醒邮件没法发送,相似Fail2ban、DDoS Deflate的重要暴力破解、DDOS攻击提醒邮件有时候仍是很重要的,错过了会给咱们的服务器运维工做带来被动的,因此明月一直在谋求Linux系统邮件发送的问题解决。服务器
yum -y install mailx
安装完成后,编辑/etc/mail.rc文件配置mailx使用QQ邮箱做为发送邮件邮箱,在配置文件最后添加以下QQ邮箱配置便可:运维
set from=xxxxxx@qq.com set smtp=smtps://smtp.qq.com:465 set smtp-auth-user=xxxxxx@qq.com set smtp-auth-password=你的QQ邮箱受权码 set smtp-auth=login set ssl-verify=ignore set nss-config-dir=/opt/.certs
由于阿里云ECS封禁了25端口,因此咱们只能使用TLS方式(TSL也就是使用SSL加密的方式,使用465或者其余端口来发送邮件)绕过25端口需求来发送邮件,因此必须先得到邮箱的SSL证书并存放到本地,最后一行的nss-config-dir就是制定的存放QQ邮箱SSL证书的位置。测试
mkdir -p /opt/.certs/ echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /opt/.certs/qq.crt certutil -A -n "GeoTrust SSL CA" -t "C,," -d /opt/.certs -i /opt/.certs/qq.crt certutil -A -n "GeoTrust Global CA" -t "C,," -d /opt/.certs -i /opt/.certs/qq.crt certutil -L -d /opt/.certs chmod -R 777 /opt/.certs #让全部用户均可以发邮件
为了防止出现前文所说的发送邮件警告提示,还须要进入邮箱SSL证书存放目录/opt/.certs里执行以下命令:阿里云
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt
返回以下提示便可:加密
**Notice: Trust flag u is set automatically if the private key is present.**
至此,已经完成了mailx结合QQ邮箱发送系统邮件的部署了,经过命令行发送测试邮件试试吧:命令行
mailx -s "邮箱测试" xxxx@qq.com < message_file.txtcode