Permalink
Browse files

Adding handling of failing DNS lookups, so script doesn't exit

  • Loading branch information...
morphex committed Sep 20, 2018
1 parent 8c8b84f commit a02dbc05d78b71aea2a086d10973eb0ec79d48c3
Showing with 33 additions and 23 deletions.
  1. +33 −23 surveil.py
View
@@ -79,16 +79,23 @@ def message(filename):
subtype=imghdr.what(None, data))
domain = sys.argv[1].split('@')[-1]
for MX in DNS.mxlookup(domain):
host = MX[1]
while 1:
try:
connection = smtplib.SMTP(host)
connection.send_message(msg)
connection.close()
print("Sent email")
break
except:
pass
for MX in DNS.mxlookup(domain):
host = MX[1]
try:
connection = smtplib.SMTP(host)
connection.send_message(msg)
connection.close()
print("Sent email")
return
except:
pass
break
except Exception:
print("Error sending mail: ")
print(sys.exc_info())
time.sleep(5) # So we don't spam the system
def message_video(directory):
msg = EmailMessage()
@@ -107,21 +114,24 @@ def message_video(directory):
subtype='plain', filename='out.log.txt')
domain = sys.argv[1].split('@')[-1]
for MX in DNS.mxlookup(domain):
host = MX[1]
while 1:
try:
connection = smtplib.SMTP(host)
connection.send_message(msg)
connection.close()
#os.unlink(directory + "/done.txt")
os.system("rm %s/*" % directory)
print("Sent email")
break
except:
pass
for MX in DNS.mxlookup(domain):
host = MX[1]
try:
connection = smtplib.SMTP(host)
connection.send_message(msg)
connection.close()
os.system("rm %s/*" % directory)
print("Sent email")
return
except:
pass
except Exception:
print("Error sending mail: ")
print(sys.exc_info())
time.sleep(5) # So we don't spam the system
def setup_video():
valid_files = []
for file in glob.glob('images/*.jpg'):

0 comments on commit a02dbc0

Please sign in to comment.