Ali cloud to create e-mail alerts python script execution timeout

Phenomenon:
do a mail alert script, python written name mail.py, reads as follows

#!/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])

But always a timeout when executing python script, can not be performed, and the same script to run correctly on your virtual machine, to see a lot of information is a copy and paste and so on, there is no such problem summary.
Himself inadvertently thought might be aliyun have been restricted to 25 ports, in order to validate their own ideas, instead of the 25-port 80 after the script smtpdm.aliyun.com

Test:
Run the command modified on two different machines aliyun

[root@iZm5exxxxxxxxxx ~]# python mail.py '[email protected]' 'teest' 'testtt'
[root@axxxxxx ~]# ./mail.py [email protected] "hello" "hello"

The results are as follows
Ali cloud to create e-mail alerts python script execution timeout
Ali cloud to create e-mail alerts python script execution timeout
success!

Summary:
aliyun send e-mail alerts python timeout, change the port number

Guess you like

Origin blog.51cto.com/11530642/2417262