wrap sending email in try except

Sometimes the recipient email may no longer be valid due to many
reasons.  Handle the failure to send email gracefully.

Signed-off-by: Dennis Gilmore <dennis@ausil.us>
This commit is contained in:
Dennis Gilmore 2017-01-16 08:00:27 -06:00 committed by Mike McLean
parent 55d57495d3
commit 60f0859591

View file

@ -419,9 +419,12 @@ refer to the document linked above for instructions."""
else:
if options.debug:
print "Sending warning notice to %s" % msg['To']
s = smtplib.SMTP(options.smtp_host)
s.sendmail(msg['From'], msg['To'], msg.as_string())
s.quit()
try:
s = smtplib.SMTP(options.smtp_host)
s.sendmail(msg['From'], msg['To'], msg.as_string())
s.quit()
except:
print "FAILED: Sending warning notice to %s" % msg['To']
def main(args):