Error handling when sending messages
This commit is contained in:
parent
1ea3ea34c1
commit
eb40179a27
|
@ -217,11 +217,23 @@ while PublicIP <= 2:
|
||||||
SmtpSubject = "[ip2e-daemon] ["+CurrentTime+"] IP has changed"
|
SmtpSubject = "[ip2e-daemon] ["+CurrentTime+"] IP has changed"
|
||||||
SmtpHeader = "From: "+FromEmail+"\n"+"To: "+ToEmail+"\n"+"Subject: "+SmtpSubject+"\n"
|
SmtpHeader = "From: "+FromEmail+"\n"+"To: "+ToEmail+"\n"+"Subject: "+SmtpSubject+"\n"
|
||||||
SmtpBodyMessage = SmtpHeader+"\n"+"[ip2e] New IP is "+NewIP+"\n\n"
|
SmtpBodyMessage = SmtpHeader+"\n"+"[ip2e] New IP is "+NewIP+"\n\n"
|
||||||
server = smtplib.SMTP(SmtpFromEmail)
|
try:
|
||||||
server.ehlo()
|
server = smtplib.SMTP(SmtpFromEmail)
|
||||||
server.starttls()
|
server.ehlo()
|
||||||
server.ehlo()
|
server.starttls()
|
||||||
server.login(FromEmailUser,FromEmailPass)
|
server.ehlo()
|
||||||
|
server.login(FromEmailUser,FromEmailPass)
|
||||||
|
except:
|
||||||
|
if os.name == "posix":
|
||||||
|
print (chr(27)+"[1;31m"+"[ip2e-daemon] ["+CurrentTime+"] Failed to connect ("+SmtpFromEmail+")")
|
||||||
|
print (chr(27)+"[1;31m"+"[ip2e-daemon] ["+CurrentTime+"] Check your settings [Aborted]")
|
||||||
|
elif os.name == "nt":
|
||||||
|
RedColor()
|
||||||
|
print ("[ip2e-daemon] ["+CurrentTime+"] Failed to connect ("+SmtpFromEmail+")")
|
||||||
|
print ("[ip2e-daemon] ["+CurrentTime+"] Check your settings [Aborted]")
|
||||||
|
editlog.write("[ip2e-daemon] ["+CurrentTime+"] Failed to connect ("+SmtpFromEmail+")\n")
|
||||||
|
editlog.write("[ip2e-daemon] ["+CurrentTime+"] Check your settings [Aborted]\n")
|
||||||
|
exit(1)
|
||||||
#Check sending errors
|
#Check sending errors
|
||||||
try:
|
try:
|
||||||
server.sendmail(FromEmail, ToEmail, SmtpBodyMessage)
|
server.sendmail(FromEmail, ToEmail, SmtpBodyMessage)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user