Added error handling when sending messages

This commit is contained in:
clamsawd 2015-10-27 20:21:14 +01:00
parent ecf2f1a092
commit b65eaa947e
3 changed files with 22 additions and 10 deletions

View File

@ -10,7 +10,7 @@
# Dependences: curl, wget, sendEmail, libio-socket-ssl-perl |
# Compatible with Python 3.x |
# --------------------------------------------------------------
version="0.3-alpha"
version="0.5-alpha"
#Import python-modules
import os

View File

@ -10,7 +10,7 @@
# Dependences: curl, wget, sendEmail, libio-socket-ssl-perl |
# Compatible with Python 3.x |
# --------------------------------------------------------------
version="0.3-alpha"
version="0.5-alpha"
#Import python-modules
import subprocess
@ -185,15 +185,27 @@ while PublicIP <= 2:
print ("[ip2e-daemon] New IP - From "+CurrentIP+" to "+NewIP)
os.system("echo [ip2e-daemon] New IP - From "+CurrentIP+" to "+NewIP+" >> ip2e.log")
MailMessage="[ip2e-daemon] Email was sent successfully"
try:
SendEmailOK = 1
while SendEmailOK <= 2:
if os.name == "posix":
os.system("sendEmail -q -f "+FromEmail+" -t "+ToEmail+" -u '[ip2e-daemon] IP has changed' -m '[ip2e] New IP is '"+NewIP+" -s "+SmtpFromEmail+" -xu "+FromEmailUser+" -xp "+FromEmailPass)
ErrorSendEmail = os.system("sendEmail -q -f "+FromEmail+" -t "+ToEmail+" -u '[ip2e-daemon] IP has changed' -m '[ip2e] New IP is '"+NewIP+" -s "+SmtpFromEmail+" -xu "+FromEmailUser+" -xp "+FromEmailPass)
elif os.name == "nt":
os.system("sendEmail -q -f "+FromEmail+" -t "+ToEmail+" -u [ip2e-daemon] IP has changed -m [ip2e] New IP is "+NewIP+" -s "+SmtpFromEmail+" -xu "+FromEmailUser+" -xp "+FromEmailPass)
except:
ErrorSendEmail = os.system("sendEmail -q -f "+FromEmail+" -t "+ToEmail+" -u [ip2e-daemon] IP has changed -m [ip2e] New IP is "+NewIP+" -s "+SmtpFromEmail+" -xu "+FromEmailUser+" -xp "+FromEmailPass)
if ErrorSendEmail == 0:
MailMessage="[ip2e-daemon] Email was sent successfully"
print (MailMessage+" ("+ToEmail+")")
os.system("echo "+MailMessage+" to "+ToEmail+" >> ip2e.log")
SendEmailOK += 2
else:
MailMessage="[ip2e-daemon] Fail to send email"
print (MailMessage+" ("+ToEmail+")")
os.system("echo "+MailMessage+" to "+ToEmail+" >> ip2e.log")
print ("[ip2e-daemon] Retrying in 5 seconds...")
os.system("echo [ip2e-daemon] Retrying in 5 seconds... >> ip2e.log")
if os.name == "posix":
os.system("sleep 5")
elif os.name == "nt":
os.system("ping -n 5 localhost>nul")
if os.name == "posix":
os.system("rm current-ip.py")
elif os.name == "nt":

View File

@ -10,7 +10,7 @@
# Dependences: curl, wget, sendEmail, libio-socket-ssl-perl |
# Compatible with Python 3.x |
# --------------------------------------------------------------
version="0.3-alpha"
version="0.5-alpha"
#Import python-modules
import os