from logging import handlers
class A:
filename = 'file'
lineno = 1
handler = handlers.SMTPHandler(('localhost', 25), 'x@x', 'y@y', 'subj')
handler.emit(A())
Вот такой попробуй со своим адресом.
Вообще, это проблема logging. Парень, который его реализовывает, хорошо пишет документацию, но хреново пишет код. Там много всяких неконсистентных моментов. Задумка хорошая, а реализация так себе.
В частности здесь timeout упрятан как служебный атрибут и выставлен в магическое число, хотя должен передаваться в качестве параметра.
/usr/lib/python2.7/logging/handlers.py
class SMTPHandler(logging.Handler):
"""
A handler class which sends an SMTP email for each logging event.
"""
def __init__(self, mailhost, fromaddr, toaddrs, subject,
credentials=None, secure=None):
"""
Initialize the handler.
Initialize the instance with the from and to addresses and subject
line of the email. To specify a non-standard SMTP port, use the
(host, port) tuple format for the mailhost argument. To specify
authentication credentials, supply a (username, password) tuple
for the credentials argument. To specify the use of a secure
protocol (TLS), pass in a tuple for the secure argument. This will
only be used when authentication credentials are supplied. The tuple
will be either an empty tuple, or a single-value tuple with the name
of a keyfile, or a 2-value tuple with the names of the keyfile and
certificate file. (This tuple is passed to the `starttls` method).
"""
logging.Handler.__init__(self)
if isinstance(mailhost, tuple):
self.mailhost, self.mailport = mailhost
else:
self.mailhost, self.mailport = mailhost, None
if isinstance(credentials, tuple):
self.username, self.password = credentials
else:
self.username = None
self.fromaddr = fromaddr
if isinstance(toaddrs, basestring):
toaddrs = [toaddrs]
self.toaddrs = toaddrs
self.subject = subject
self.secure = secure
self._timeout = 5.0
...
Это же просто писец какой-то. Если сервер находится дальше пяти секунд, то логгером нельзя пользоваться. В документации о служебном атрибуте нет ни слова, следовательно таймаут нельзя менять. (Его использование - это хак, а хаки легко слетают при выходе новых версий ПО.)
Вот на этом можешь проверить подключение к своему серверу:
from logging import handlers
class S(handlers.SMTPHandler):
def __init__(self, *args, **kwargs):
super(self.__class__, self).__init__(*args, **kwargs)
self._timeout = 10.0
class A:
filename = 'file'
lineno = 1
SMTP = handlers.SMTPHandler
SMTP = S
handler = SMTP(('localhost', 25), 'x@x', 'y@y', 'subj')
handler.emit(A())
А, ну вот:
Таймаут был зашит
https://docs.python.org/2/library/logging.handlers.html#smtphandlerКто-то напоролся и таймаут появился
https://docs.python.org/3/library/logging.handlers.html#smtphandlerДаже вон кто
http://bugs.python.org/issue14314David Murray - один из разработчиков.