【錯誤彙總】阿里雲建立郵件告警 python 腳本,執行超時

現象:
作了一個郵件告警腳本,python 寫的,名稱 mail.py,內容以下python

#!/usr/bin/python
#coding:utf-8

import smtplib
from email.mime.text import MIMEText
import sys

mail_user = 'admin@axxxxxxxxxxx.cn'
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端口ide

測試:
分別在兩臺不一樣的aliyun機器上執行了修改後的命令測試

[root@iZm5exxxxxxxxxx ~]# python mail.py 'zxxxxxxxx@163.com' 'teest' 'testtt'
[root@axxxxxx ~]# ./mail.py zxxxxxxxx@163.com "hello" "hello"

結果以下
【錯誤彙總】阿里雲建立郵件告警 python 腳本,執行超時
【錯誤彙總】阿里雲建立郵件告警 python 腳本,執行超時
成功!阿里雲

總結:
aliyun發python郵件告警超時,更改端口號code

相關文章
相關標籤/搜索