examples of logger using smtp
Vinay Sajip
vinay_sajip at yahoo.co.uk
Fri Jan 18 03:16:21 EST 2008
On Jan 17, 7:46 pm, Rob Wolfe <r... at smsnet.pl> wrote:
>
> If you need to use smtp authentication there is a small problem
> with `SMTPHandler`. Actually, you need to subclass `SMTPHandler`
> and override `emit` method, e.g.:
>
> fromloggingimport getLogger, Formatter, DEBUG
> fromlogging.handlers import SMTPHandler
>
> class SMTPAuthHandler(SMTPHandler):
> def __init__(self, mailhost, fromaddr, toaddrs, subject,
> user=None, password=None):
> SMTPHandler.__init__(self, mailhost, fromaddr, toaddrs, subject)
> self.user = user
> self.password= password
>
[snip]
Although the code in the last release does not support authentication
(hence needing the above code), the code currently in SVN does support
it. Instead of separate user and password arguments, a new
"credentials" optional argument ((user, password) tuple, defaulting to
None) has been added. So if you are using Rob Wolfe's approach, it may
be easier for you to use "credentials" because your code will not need
to change when Python 2.6 appears.
Best regards,
Vinay Sajip
More information about the Python-list
mailing list