现象:
做了一个邮件告警脚本, python 写的, 名称 mail.py, 内容如下
- #!/usr/bin/python
- #coding:utf-8
- import smtplib
- from email.mime.text import MIMEText
- import sys
- mail_user = '[email protected]'
- mail_pass = '8xxxxxxxxxxxxj'
- def send_mail(to_list,subject,content):
- me = "zabbix 监控告警平台"+"<"+mail_user+">"
- msg = MIMEText(content, 'plain', 'utf-8')
- msg['Subject'] = subject
- msg['From'] = me
- msg['to'] = to_list
- try:
- s = smtplib.SMTP("smtpdm.aliyun.com", 25)
- s.login(mail_user,mail_pass)
- s.sendmail(me,to_list,msg.as_string())
- s.close()
- return True
- except Exception,e:
- print str(e)
- return False
- if __name__ == "__main__":
- send_mail(sys.argv[1], sys.argv[2], sys.argv[3])
但是在执行 python 脚本时总是超时, 无法执行, 而同一个脚本在自己虚拟机上能正常运行, 查看了不少资料都是复制粘贴云云, 没有此类问题汇总.
自己无意中想到可能是 aliyun 对 25 端口做了限制, 为了验证自己的想法, 将脚本中的 smtpdm.aliyun.com 后的 25 改为了 80 端口
测试:
分别在两台不同的 aliyun 机器上执行了修改后的命令
- [[email protected] ~]# python mail.py '[email protected]' 'teest' 'testtt'
- [[email protected] ~]# ./mail.py [email protected] "hello" "hello"
结果如下
成功!
总结:
aliyun 发 python 邮件告警超时, 更改端口号
来源: http://www.bubuko.com/infodetail-3113402.html