BTS交易机器人(8)-发送邮件配置(BTS trading bot)

in cn •  7 years ago  (edited)

​ 在VPS上要能够发送邮件,以便交易程序出问题时及时得到通知。这个发送邮件的功能我折腾了好久,我把碰到的坑给大家分享,以免走弯路。

  • 坑1: 检查25号端口是否正常

    之前百度云申请的VPS,可以直接发送邮件,发送邮件的命令如下所示:

​ echo "content" |mail -s "title" [email protected]

​ 其中content为邮件的内容,title为邮件的标题,[email protected]为目的邮件地址。

​ 可是在阿里云上就行不通了,虽然命令执行完毕,但是邮件并没有发出去。中间折腾了好久,终于学习到一些常识:发送邮件是与目标邮件服务器25号端口通讯,判断能否发送邮件,可以运行下面的命令:

​ telnet smtp.xxx.xxx 25

​ 如果出现长时间出现Trying x.x.x.x...,说明无法连接,可以试验一下一些知名服务器,比如smtp.qq.com,如果也都不行,说明25号出端口可能有问题,检查防火墙是否拦截了此端口,如果都没有问题,那么就可能是你的主机提供商把此端口封掉了。不错,阿里云就是这样,默认是关闭的,不过可以申请解封,在“我的账号”-“安全管控”-“25号端口解封”菜单项,我申请了,不过被拒绝了,联系客服,他们说一般不会解封的,但是可以通过465端口发送邮件,必须通过第三方邮件提供商发送。

  • 坑2:找一个支持465端口的邮件提供商

    于是我申请了一个阿里云个人邮箱,经过telnet测试,发现是OK的,如下所示,于是我就开始下一步的配置。

    ~#telnet smtp.aliyun.com 465
    Trying 140.205.94.10...
    Connected to smtp.aliyun.com.
    Escape character is '^]'.

参考文章“[基础常识]在CentOS 7系统里使用465端口发送邮件https://bbs.aliyun.com/read/316576.html” ,配置完之后,发现仍然不能发送邮件,无论服务器使用smtp.aliyun.com还是使用smtp.mxhichina.com,均提示认证失败,在网络上搜索了一下,发现能够发送成功的例子都是使用的阿里云邮箱的企业版,个人版邮箱没有发现成功的案例。于是猜测可能只有企业邮箱才可以。试图申请企业邮箱时,才发现要填写的内容很多,还要交钱。终于明白了,阿里云打着防止垃圾邮件的旗号封禁了25号端口,实质上是售卖他们自己的邮件服务。

​ 于是果断放弃了阿里,使用QQ邮箱,这里有一个特别需要注意的地方,smtp-auth-password的密码并不是QQ账号的密码、也不是QQ邮箱的密码,而是在PC版QQ邮箱的设置界面中申请的授权码,详细申请过程就不介绍了,大家自己查阅就好了。

  • 坑3:解决证书没有认可的提示

    配置完QQ邮箱的SMTP之后,最终结果如下所示:

    set from="[email protected]"
    set smtp="smtps://smtp.qq.com:465"
    set smtp-auth=login
    set smtp-auth-user="[email protected]"
    set smtp-auth-password="xxxxxxx"
    set ssl-verify=ignore
    set nss-config-dir="/root/.certs"

    这里面特别注意的是,一定要设置set from="xxx",否则发送时会提示发件人不一致。

    实际发送时虽然能够发送成功,但是一直报下面的错误提示:

    Error in certificate: Peer's certificate issuer is not recognized.

    参考此文章,问题才最终得到解决《mailx及sendEmail的基本用法比较 http://blog.51cto.com/irow10/1812638》

    输入下面的命令行即可(我完全不明白是什么意思,照此输入,果然OK了)

    echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/qq.crt

    certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt

    certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt

    certutil -L -d /root/.certs

    certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt

BTS交易机器人(1)-选购VPS(BTS trading bot) https://steemit.com/cn/@brysj22952/bts-1-vps-bts-trading-bot
BTS交易机器人(2)-运行环境(BTS trading bot) https://steemit.com/cn/@brysj22952/bts-2-bts-trading-bot
BTS交易机器人(3)-Python升级(BTS trading bot) https://steemit.com/cn/@brysj22952/bts-3-python-bts-trading-bot
BTS交易机器人(4)-把Vim改造成简易Python编辑器(BTS trading bot) https://steemit.com/cn/@brysj22952/bts-4-vim-python-bts-trading-bot
BTS交易机器人(5)-安装pip3(BTS trading bot) https://steemit.com/cn/@brysj22952/bts-5-pip3-bts-trading-bot
BTS交易机器人(6)-安装uptick(BTS trading bot)https://steemit.com/cn/@brysj22952/bts-6-uptick-bts-trading-
BTS交易机器人(7)-安装其它依赖组件,配置uptick(BTS trading bot) https://steemit.com/cn/@brysj22952/2ymagn-bts-6-uptick-bts-trading-bot​

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

The Vote For Your Awesome Post Has Just Arrived!


This post has been voted with the use of SteemiTag. Feel free to upvote this comment if you’d like to express your support for our cause. Conversely, if you don’t want to receive any more votes from SteemiTag, please respond to this comment by writing NOVOTES.

SteemiTag is an innovative program that helps users increase their gains in the curation rewards by voting on posts that are likely to get high payouts. It maximizes the chance of a user to be rewarded through an accurate selection algorithm that works 24/7 and eliminates "no rewards" problem for users with low Steem Power. You can participate in our program by clicking on this link and confirming your delegation. Your rewards will be sent to you in the form of weekly dividends. Thank you and keep up with your great work!