python smtplib set timeout -


I am trying to write small applications to send content status to my server every day, I am using smtplib I have a little problem with the bat, I can not know the connection timeout! Try Cubes smtp.setdefaulttimeout (30) BAT do not work

  try def connect (host, user, password): smtp = smtplib.SMTP (host) smtp.login (user, password) Code = Smtp.ehlo () [0] If no (200 =   

How to set connection timeout for this function? Thank you

With Python 2.6 you can set the timeout in the SMTP Library:

  class smtplib.SMTP ([host [, port [, local_hostname [, timeout]]]   

"if not specified, global default timeout setting"

If you use an earlier version of Python (& lt; 2.6), then you have to set the socket default timeout:

  import socket socket Setdefaulttimeout (120 )   

worked fine for me.

Comments

Popular posts from this blog

c - Performance of System() -

python - how we can use ajax() in views.py in django? -

c++ - How to define methods in a base class that only work in derived classes? -