473,387 Members | 1,542 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

(solved) smtplib, capturing output from set_debuglevel ??

----- Original Message -----
From: "Tim Williams" <li********@tdw.net>
----- Original Message -----
From: "Steve Holden" <st***@holdenweb.com> [snip] Yeah, I did wonder about changing the code (though it's not my first
choice. I've done it before and caught a crab later), or could I do it
with Subclassing?

I'm still close to Newbie status, so I can't immediately imagine what I
could change the smptblib code to write to, or how to subclass to get
the behaviour I might need.


Doh, still thinking of myself as close to newbie scares me off some things
!!

I decided to bite the bullet and have a look at the code for smtplib,
(after being scared of changing it before), and of course its what I
should have done in the first place.

The debug output in smptlib is generated in the SMTP class with lines
similar to:

if self.debuglevel > 0: print "connect:", msg

so, I added a new variable within the class

debug_out = []

and 2 new functions within the class

def do_debug(self,msgs):
if self.debuglevel > 0: print msgs
self.debug_out.append(msgs)

def debug(self):
return self.debug_out

and changed

if self.debuglevel > 0: print "connect:", msg

to

self.do_debug( ('connect:', msg ) )

Took me about 4 minutes !!

now I can call s.debug() and get a list containing the debug information.
s.debug() can be called at anytime including after s.quit()

As a side benefit, I can use s.do_debug( msg ) at any time to get the
program to add (comment) lines to the debug information. This will be
useful when reading the full retrieved debug information at a later date.

set_debuglevel() works exactly as it did before.

I have to tidy up the formatting/handling of the messages, and I think I'm
going to add an option to retrieve the debug information without the
message data (as its usually superfluous to the debugging process) , but
other than that it does just what I need already.

Is it worth asking for something like this to be added permanently to
smtplib, I can't be the only one that needs to log outgoing smtp
conversations, or debug to a file/log ?

Thanks for everyone's help

Tim




Jul 18 '05 #1
2 3169
Tim Williams wrote:
----- Original Message -----
From: "Tim Williams" <li********@tdw.net>
----- Original Message -----
From: "Steve Holden" <st***@holdenweb.com>
[snip]
Yeah, I did wonder about changing the code (though it's not my first
choice. I've done it before and caught a crab later), or could I do it
with Subclassing?

[...Tim fixes smtplib...]
Took me about 4 minutes !!

now I can call s.debug() and get a list containing the debug information.
s.debug() can be called at anytime including after s.quit()

As a side benefit, I can use s.do_debug( msg ) at any time to get the
program to add (comment) lines to the debug information. This will be
useful when reading the full retrieved debug information at a later date.

set_debuglevel() works exactly as it did before.

I have to tidy up the formatting/handling of the messages, and I think I'm
going to add an option to retrieve the debug information without the
message data (as its usually superfluous to the debugging process) , but
other than that it does just what I need already.

Is it worth asking for something like this to be added permanently to
smtplib, I can't be the only one that needs to log outgoing smtp
conversations, or debug to a file/log ?

Thanks for everyone's help

Correct action under these circumstances would be to submit a patch.
This sounds intimidating of you've never done it before, but the process
isn;t that difficult once you've created your SourceForgew account, and
there are meny experienced hands on the list who will help you if you
get stuck.

regards
Steve
--
http://www.holdenweb.com
http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119
Jul 18 '05 #2
Tim Williams wrote:
----- Original Message -----
From: "Tim Williams" <li********@tdw.net>
----- Original Message -----
From: "Steve Holden" <st***@holdenweb.com>
[snip]
Yeah, I did wonder about changing the code (though it's not my first
choice. I've done it before and caught a crab later), or could I do it
with Subclassing?

[...Tim fixes smtplib...]
Took me about 4 minutes !!

now I can call s.debug() and get a list containing the debug information.
s.debug() can be called at anytime including after s.quit()

As a side benefit, I can use s.do_debug( msg ) at any time to get the
program to add (comment) lines to the debug information. This will be
useful when reading the full retrieved debug information at a later date.

set_debuglevel() works exactly as it did before.

I have to tidy up the formatting/handling of the messages, and I think I'm
going to add an option to retrieve the debug information without the
message data (as its usually superfluous to the debugging process) , but
other than that it does just what I need already.

Is it worth asking for something like this to be added permanently to
smtplib, I can't be the only one that needs to log outgoing smtp
conversations, or debug to a file/log ?

Thanks for everyone's help

Correct action under these circumstances would be to submit a patch.
This sounds intimidating of you've never done it before, but the process
isn;t that difficult once you've created your SourceForgew account, and
there are meny experienced hands on the list who will help you if you
get stuck.

regards
Steve
--
http://www.holdenweb.com
http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Frank Zheng | last post by:
I wrote some code to test "smtplib", but i met a problem when i call the "login(user,pass)" of the "SMTP" object. here are the codes: >>> s = smtplib.SMTP() >>> s.set_debuglevel(1) >>>...
8
by: dccarson | last post by:
Here is a snippet of code which does not send to all recipients. However, it also does not inform me of this error. My suspicion is that this only fails for users with longer usernames. The two I...
0
by: Tim Williams | last post by:
I have a working SMTP client that I need to add TLS capability to, I absolutely need the client to timeout within a specified time, but when I use the sock.timeout() line it freezes the reading...
0
by: praba kar | last post by:
Dear All, I have doubt regarding mail sending smtplib module. The below code is I used to send a mail. ########################################## import email.Message import email.Utils...
6
by: Matthias Kluwe | last post by:
Hi! After getting a @gmail.com address, I recognized I had to use TLS in my python scripts using smtplib in order to get mail to the smtp.gmail.com server. Things work well so far, apart from...
2
by: carl.reimann | last post by:
In using a simple smtp routine: # begin example >>> import smtplib >>> server = smtplib.SMTP('outgoing.verizon.net') >>> server.sendmail('my@address.net', 'another@address.net', """To:...
8
by: NicolasG | last post by:
I'm using the following code to send e-mail through python: import smtplib fromaddr = 'myMail@gmail.com' toaddrs = 'myOtherMail@gmail.com' subject = 'someting for subject !' msg = 'This...
2
by: carlistixx | last post by:
Hi, I'm using the roundup issue tracker (http://roundup.sourceforge.net) which uses smtplib to send mail. It all worked until we moved to a hosted Exchange MTA. The hosting provider requires the...
1
by: Hunter | last post by:
I am writing a script that needs to send some emails. And I've used smtplib in the past and it is pretty easy. But I thought, gee it would be easier if I could just call it as a function, passing...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.