smtplib
prints directly to stderr
, for example. line 823 in smtplib.py:
print>>stderr, 'connect fail:', host
You will need either the monkey sys.stderr patch until you import smtplib
or smtplib.stderr
until you run your mail code.
I can also suggest a fix to smtplib.stderr
using a custom object that has a write
method to port your logging code (for example, if you use the log library):
import logging import smtp class StderrLogger(object): def __init__(self): self.logger = logging.getLogger('mail') def write(self, message): self.logger.debug(message) org_stderr = smtp.stderr smtp.stderr = StderrLogger()
This question contains some useful examples of fixing stderr with context managers.
source share