
Ich habe unten ein kleines Python-Skript, das E-Mails an die Outlook-E-Mail-Adresse meines Unternehmens sendet. Auf meinem privaten Computer funktioniert es einwandfrei, aber wenn ich es auf dem Server bereitstelle, läuft es ständig, es tritt eine Zeitüberschreitung auf, aber es werden keine E-Mails gesendet.
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()
Unten sehen Sie den Fehler, wenn es zu einer Zeitüberschreitung kommt.
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
Ich kann keine Verbindung per Telnet zu Outlook herstellen, es tritt auch eine Zeitüberschreitung auf. Siehe unten: -
[linux_server Python]$ telnet smtp.outlook.com 587
Trying 40.101.4.2...
^C
[linux_server Python]$
unten sind die Abhörports auf diesem Server.
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]$
Kann mir jemand helfen, das Problem zu verstehen und es zu beheben? Oder gibt es eine andere Möglichkeit, dieses E-Mail-Sendeskript zu konfigurieren? Jede Hilfe ist willkommen. Vielen Dank im Voraus!