技术干货

阿里云ECS命令行发送邮件配置

2019-12-27  本文已影响0人  程序员大春

知识点

环境

背景

编写服务监听脚本,发生异常发送邮件通知管理员

阿里云企业邮箱smtp地址以及配置

http://mailhelp.mxhichina.com/smartmail/admin/detail.vm?knoId=5871700

阿里云ECS如何在命令行发送邮件

yum install -y mailx
vim /etc/mail.rc
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/root/.certs
set from=system@yunliantaida.com
set smtp="smtps://smtp.mxhichina.com:465"
set smtp-auth-user=system@yunliantaida.com
set smtp-auth-password=xxxx

如何使用mailx配置ssl安全证书

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

测试发送

echo "nihao" |mail -v -s "test mailx" lianwanchun@yunliantaida.com

执行到这儿一般会报错

issuer=CN=GlobalSign Organization Validation CA - SHA256 - G2,O=GlobalSign nv-sa,C=BE
subject=CN=*.mxhichina.com,O="Alibaba (China) Technology Co., Ltd.",L=HangZhou,ST=ZheJiang,C=CN
220 smtp.aliyun-inc.com MX AliMail Server
>>> EHLO taigao-ecs-01
250-smtp.aliyun-inc.com
250-8BITMIME
250-AUTH=PLAIN LOGIN XALIOAUTH
250-AUTH PLAIN LOGIN XALIOAUTH
250-PIPELINING
250 DSN
>>> AUTH LOGIN
334 dXNlcm5hbWU6
>>> c3lzdGVt
334 UGFzc3dvcmQ6
>>> WXVubGlhbnRhaWRhMTAxOQ==
526 Authentication failure[0]
smtp-server: 526 Authentication failure[0]
"/root/dead.letter" 11/353
. . . message not sent.

没关系在执行

cd /root/.certs
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu"  -d ./ -i ./mxhichina.crt

在此发送就会成功了

上一篇 下一篇

猜你喜欢

热点阅读