>Not surprisingly, the exception you should catch is simply TimeoutError:
> server.sendmail(sender, receivers, msg.as_string())
> except TimeoutError as e:
> print("SMTP could not be contacted: %s" % e)
The error was thrown by another line :S, after putting the TimeoutError it work
OK (with the proper exception line).
I had to apply a WA server = None to avoid the finally " UnboundLocalError:
local variable 'server' referenced before assignment "
server = None
server = smtplib.SMTP('smtp.mail.com') <--- this is where the
exception was happening.
server.set_debuglevel(True) # show communication with the server
server.sendmail(sender, receivers, msg.as_string())
except TimeoutError as e:
print("SMTP could not be access: %s"%e)
This email is confidential and may be subject to privilege. If you are not the
intended recipient, please do not copy or disclose its content but contact the
sender immediately upon receipt.