700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 阿里云服务器使用命令行上发送邮件

阿里云服务器使用命令行上发送邮件

时间:2024-05-23 00:13:54

相关推荐

阿里云服务器使用命令行上发送邮件

阿里云服务器是不允许使用25端口发邮件,25端口默认是被占用的,因此我们一般使用465端口号进行邮件的发送,先在阿里云上将465端口号开放

通过以上步骤获取授权码,复制下来

启动postfix

service postfix start

chkconfig postfix on

如果启动失败,运行

postfix check

如果出现 postfix: error while loading shared libraries: libmysqlclient.so.16: cannot open shared object file: No such file or directory ,则运行下面两行

rpm -qa|grep mysql

yum install mysql-libs

创建认证(关键)

在命令行中依次执行以下命令

mkdir -p /root/.certs/ ##先创建这个文件夹echo -n | openssl s_client -connect :465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/qq.crtcertutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crtcertutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crtcertutil -L -d /root/.certscd /root/.certscertutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt

配置main.rc

vim /etc/mail.rcset from=1614674987@ ##你发邮件的邮箱set smtp=smtps://:465set smtp-auth-user=1614674987@ ## qq邮箱set smtp-auth-password=dqiqzlqpslvxdieb #你自己的授权码set smtp-auth=loginset smtp-use-starttlsset ssl-verify=ignoreset nss-config-dir=/root/.certs

下载 mailx

yum -y install mailx

配置阿里云的证书

chmod 644 /root/.cert/*cd /root/.certs # 一定要进入该目录下,要不然之后执行的命令会报错,或者是权限不是644certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i .crt #.crt是阿里云的证书echo -n | openssl s_client -connect smtp.:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/.crtcertutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/.crtcertutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/.crt#执行完以后再次查看发现.crt存在了,之后执行certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i .crt# Notice: Trust flag u is set automatically if the private key is present. 【这才是正确的结果】

测试一下

echo "hello word" | mail -s "title" 1614674987@(收邮件的邮箱)

# 如果出现SSL/TLS handshake failed: SSL received a malformed Alert record."/root/dead.letter" 11/306. . . message not sent.

/etc/main.rc中把set smtp-use-starttls给去掉, 之后再测试一下,即可收到邮箱

作用

用命令行发邮件的作用是可以将命令写在脚本之中,从而实现自动化,可以用在自动化部署当中,如果部署完成了可以发一封邮件告诉你部署成功或失败

感谢大佬的文章使用阿里云服务器写shell脚本发送qq邮件的三个形式

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。