
Eu tenho um pequeno script python abaixo que envia e-mails para o e-mail do Outlook da minha empresa. funciona bem no meu computador pessoal, mas quando estou implantando-o no servidor, ele continua funcionando e atinge o tempo limite, mas não envia e-mail.
import os
import smtplib
import subprocess
from sys import exit
cmd = 'df -kh'
p1 = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
std,err = p1.communicate()
output=std.decode()
#print (output)
smtp=smtplib.SMTP('smtp.outlook.com', 587)
smtp.ehlo()
smtp.starttls()
smtp.ehlo()
smtp.login('email','password')
subject = 'Send_Disk_Info_Daily'
body = output;
msg = (("subject : {} ".format(subject))+("\n\n{}".format(body)))
smtp.sendmail('email', 'email',msg)
smtp.quit()
Abaixo está o erro quando atinge o tempo limite-
Traceback (most recent call last):
File "send_disk_info.py", line 16, in <module>
smtp=smtplib.SMTP_SSL('smtp.outlook.com', 587, timeout=20)
File "/usr/lib64/python2.7/smtplib.py", line 789, in __init__
SMTP.__init__(self, host, port, local_hostname, timeout)
File "/usr/lib64/python2.7/smtplib.py", line 255, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib64/python2.7/smtplib.py", line 315, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib64/python2.7/smtplib.py", line 794, in _get_socket
new_socket = socket.create_connection((host, port), timeout)
File "/usr/lib64/python2.7/socket.py", line 571, in create_connection
raise err
socket.error: [Errno 101] Network is unreachable
Não consigo fazer telnet para o Outlook, o tempo limite também se esgota. Veja abaixo:-
[linux_server Python]$ telnet smtp.outlook.com 587
Trying 40.101.4.2...
^C
[linux_server Python]$
abaixo estão as portas de escuta neste servidor.
linux_server Python]$ netstat -tulpn|grep -i listen
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:199 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN -
tcp6 0 0 :::5666 :::* LISTEN -
tcp6 0 0 :::37712 :::* LISTEN 45077/java
tcp6 0 0 :::8080 :::* LISTEN 44458/java
tcp6 0 0 :::8085 :::* LISTEN 44458/java
tcp6 0 0 :::22 :::* LISTEN -
tcp6 0 0 ::1:25 :::* LISTEN -
tcp6 0 0 :::32858 :::* LISTEN 44648/java
[linux_server Python]$
Alguém pode me ajudar a entender o problema e corrigi-lo. Ou existe alguma maneira alternativa de configurar esse script de envio de e-mail. Qualquer ajuda é apreciada. Desde já, obrigado !