阿里云ECS配置mailx
目录
阿里云ECS配置mailx
由于阿里云已将25端口封了(改用465端口),所以在ECS上往外发邮件时要作相应的配置才行。
使用的是阿里云的企业邮箱,测试可用。
-
在阿里云的“安全组”开放645端口通行。
安装相应软件包:
1 2 3 4 5
systemctl stop sendmail systemctl stop postfix systemctl disable sendmail systemctl disable postfix yum -y install mailx
-
下载证书:
创建目录,用来存放证书
mkdir -p /root/.certs/
-
向163请求证书
echo -n|openssl s_client -connect smtp.mxhichina.com:465|sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/aliyun.crt
-
添加一个证书到证书数据库中
1 2
certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/aliyun.crt certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/aliyun.crt
-
使证书得到认可,避免发邮件后报错:Error in certificate: Peer’s certificate issuer is not recognized
1 2 3
cd /root/.certs # (一定要进入到证书所在目录才行) certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i ./aliyun.crt
-
列出目录下证书
certutil -L -d /root/.certs
-
mail.rc末尾追加SMTP配置:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
vim /etc/mail.rc # 加密邮件 set from=noreply@taoquanw.com set smtp=smtps://smtp.mxhichina.com:465 set smtp-auth-user=noreply@taoquanw.com set smtp-auth-password=123456 set smtp-auth=login set ssl-verify=ignore set nss-config-dir=/root/.certs # 非加密邮件(可用于非阿里云) set from=noreply@taoquanw.com set smtp=smtp://smtp.mxhichina.com:25 set smtp-auth-user=noreply@taoquanw.com set smtp-auth-password=123456 set smtp-auth=login set ssl-verify=ignore
-
测试效果:
echo 'hello'|mail -v -s "test mail" admin@taoquanw.com
-
设置root的别名邮箱
1 2 3 4
vim /etc/mail.rc alias root admin@taoquanw.com alias vagrant admin@taoquanw.com
Related Issues not found
Please contact @chariothy to initialize the comment