smtpd module

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Feb 6 18:51:12 CET 2008


En Wed, 06 Feb 2008 05:36:05 -0200, Stefan Witzel  
<stefan.witzel at zvw.uni-goettingen.de> escribi�:

> the documentation of the smtpd module in the Python Library Reference
> is very short, I think. Are there any examples available? Especially
> I'm interested in the DebuggingServer.

Yes, the documentation is rather incomplete.
SMTPServer is an abstract class; it accepts local connections and handles  
them, but doesn't know what to do with the received message. Subclasses  
must override the process_message method to do something useful.

DebuggingServer is the simplest subclass; it just prints the received  
message and nothing more, the message isn't delivered at all. Useful when  
you want to test some program that sends messages but you don't want them  
to be actually delivered.

PureProxy delivers the message to the upstream SMTP server (defined in the  
constructor). By example:

localsmtpd = smtpd.PureProxy(('localhost',2500),('smtp.whatever.com',25))
asyncore.loop()

Then you (or your MUA, or any program, or a python script using smtplib)  
can connect locally to port 2500 and send messages; they will be delivered  
to smtp.whatever.com.

You can subclass PureProxy and pre-process the message before it is sent;  
you could block some addresses, disallow attachments, add those annoying  
disclaimers... MailmanProxy, by example, is a PureProxy subclass that  
intercepts messages addressed to mailman and processes them directly.

-- 
Gabriel Genellina




More information about the Python-list mailing list