By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,909 Members | 1,775 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,909 IT Pros & Developers. It's quick & easy.

email module, redirecting to stdout

P: n/a

Hello,

I have this code:

s = smtplib.SMTP()
s.set_debuglevel(1)
s.connect(host=smtp_host)
s.set_debuglevel(0)
log("Connected, sending e-mail")
sys.stdout.flush()
s.sendmail(
consts.EMAIL_FROMADDRESS,
[to],
msg.as_string()
)
log("E-mail sent OK")
s.quit()

The problem is that whenever I set the debuglevel to 1, messages will go
to stderr. I would like them to go to stdout. Using

sys.stderr = sys.stdout

has no effect. Redirecting stderr to stdout from the shell is not an
option for me, because I need to use stderr for other messages.

Thanks,

Les

Oct 4 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Laszlo Zsolt Nagy wrote:
I have this code:

s = smtplib.SMTP()
s.set_debuglevel(1)
s.connect(host=smtp_host)
s.set_debuglevel(0)
log("Connected, sending e-mail")
sys.stdout.flush()
s.sendmail(
consts.EMAIL_FROMADDRESS,
[to],
msg.as_string()
)
log("E-mail sent OK")
s.quit()

The problem is that whenever I set the debuglevel to 1, messages will go
to stderr. I would like them to go to stdout. Using

sys.stderr = sys.stdout

has no effect. Redirecting stderr to stdout from the shell is not an
option for me, because I need to use stderr for other messages.


smtplib obtains a copy of stderr by

from sys import stderr

Therefore you have to do

smtplib.stderr = sys.stdout

to get the desired effect.

Peter


Oct 4 '05 #2

P: n/a
In article <dh*************@news.t-online.com>,
Peter Otten <__*******@web.de> wrote:
Laszlo Zsolt Nagy wrote:
I have this code:

s = smtplib.SMTP()
s.set_debuglevel(1)
s.connect(host=smtp_host)
s.set_debuglevel(0)
log("Connected, sending e-mail")
sys.stdout.flush()
s.sendmail(
consts.EMAIL_FROMADDRESS,
[to],
msg.as_string()
)
log("E-mail sent OK")
s.quit()

The problem is that whenever I set the debuglevel to 1, messages will go
to stderr. I would like them to go to stdout. Using

sys.stderr = sys.stdout

has no effect. Redirecting stderr to stdout from the shell is not an
option for me, because I need to use stderr for other messages.


smtplib obtains a copy of stderr by

from sys import stderr

Therefore you have to do

smtplib.stderr = sys.stdout

to get the desired effect.


Ouch. I'd consider this a bug. "from sys import stderr" should at least
be considered bad style.

Just
Oct 4 '05 #3

P: n/a
Just wrote:
smtplib obtains a copy of stderr by
from sys import stderr
Ouch. I'd consider this a bug. "from sys import stderr" should at least
be considered bad style.


I'd rather say this is the low-tech equivalent to

debug = logging.getLogger("smtplib").debug

an approach which is currently only taken by the cookielib module.

Peter

Oct 4 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.