>Not surprisingly, the exception you should catch is simply TimeoutError:

 >    try:
 >        server.sendmail(sender, receivers, msg.as_string())
 >    except TimeoutError as e:
 >        print("SMTP could not be contacted: %s" % e)
 >    finally:
 >       server.quit()

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
       try:
                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)
                pass
        finally:
                if server:
                        server.quit()


Joaquin
----

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.
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to