473,594 Members | 2,749 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

(solved) smtplib, capturing output from set_debuglevel ??

----- Original Message -----
From: "Tim Williams" <li********@tdw .net>
----- Original Message -----
From: "Steve Holden" <st***@holdenwe b.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,m sgs):
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 3185
Tim Williams wrote:
----- Original Message -----
From: "Tim Williams" <li********@tdw .net>
----- Original Message -----
From: "Steve Holden" <st***@holdenwe b.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***@holdenwe b.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
1723
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) >>> s.connect('smtp.263.net') connect: ('smtp.263.net', 25) connect: ('smtp.263.net', 25) reply: '220 Welcome to coremail System(With Anti-Spam) 2.1 for
8
2578
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 seem to regularly fail on have 9 and 11 characters respectively. Most users have names <= 8 characters. domain = "myDomainHere.com" admin = "d123456@%s" % domain adminFull = "Full Name Here <%s>" % admin def mailMsg(text, subject, sender,...
0
3037
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 of chars from SSLFakeFile used during TLS instead of timing out the client connection. I am working from my own hacked version of smtplib, but can demonstrate the problem using the standard module (Python 2.3.4). Can anyone suggest a...
0
522
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 import mimetypes import os,string
6
10002
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 an unexpected error. Here's my sample code: import smtplib
2
6465
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: another@address.net From: my@address.net Subject: Shakespeare Quote
8
5038
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 is body of the mail.'
2
6129
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 use of TLS. Now roundup can't send mail. My version of python is: Python 2.3.4 (#1, Feb 6 2006, 10:38:46) on linux2
1
2383
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 the from, to, subject, and message text. So I wrote it up as a function and it sort of works, but I get a weird error. When it runs it inserts a "\t" tab character before each item during the send portion (which I can see when I turn on...
0
7941
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
7874
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8246
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8000
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5404
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3854
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3895
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2383
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1476
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.