help using smptd

E

Edward Elliott

I'm having trouble using the smptd module. The docs are woefully inadequate
and inspecting the source didn't help either. So far I've figured out how
to subclass smtpd.SMTPServer and override the process_message method to
handle smtp messages. I create an instance of my server and it listens on
the given interface. I can connect to the port it's on and send SMTP
commands but it doesn't respond. I've verified that it's actually bound
and I'm connecting to the right port.

The server object doesn't appear to have any methods like poll() or loop()
to continually handle connections, which is all I want it to do. There is
a listen method but it does something else. Does SMTPServer have an
equivalent to the serve_forever method of
BaseHTTPServer.BaseHTTPRequestHandler? If not how do I handle smtp
sessions? SMTPServer derives from asyncore/asynchat, but I didn't find
what I wanted there either.


import smtpd

class SMTPProxy (smtpd.SMTPServer):
def process_message (self, peer, mailfrom, rcpttos, data):
# my code here

proxy = SMTPProxy (listen_addr, relay_addr)
# now what?
 
H

Heiko Wundram

Am Sonntag 14 Mai 2006 23:47 schrieb Dennis Lee Bieber:
Don't you need to have an __init__() that invokes SMTPServer's
__init__()?

If you don't define an __init__() yourself (as it seems to be the case here),
MRO (and the rules associated with class methods) will take care that the
base class' __init__() gets called automatically.

--- Heiko.
 
E

Edward Elliott

Heiko said:
If you don't define an __init__() yourself (as it seems to be the case
here), MRO (and the rules associated with class methods) will take care
that the base class' __init__() gets called automatically.

Yes __init__ is being called. smtpd.PureProxy doesn't define its own init
either and it shows the same behavior as my class: binds to the port but
doesn't respond to connections.
 
E

Edward Elliott

Edward said:
import smtpd

class SMTPProxy (smtpd.SMTPServer):
def process_message (self, peer, mailfrom, rcpttos, data):
# my code here

proxy = SMTPProxy (listen_addr, relay_addr)
# now what?

Update: I think I've solved it. SMTPServer registers with asyncore, so the
'now what' to handle connections is this:

asyncore.loop()

I tried that once before I posted without success, however I think I had
accidentally closed the socket already.

Now a follow-up question: does anyone know the purpose of the timeout
parameter to loop()? The asyncore docs say this:

"The timeout argument sets the timeout parameter for the appropriate
select() or poll() call, measured in seconds; the default is 30 seconds."

According to the select man page, timeout determines how long it blocks
before returning. But AFAICT, asyncore.loop() runs forever (as long as a
channel is open) no matter how long select blocks. What's the point of
passing a timeout for select when loop just calls it again every time it
returns?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,158
Latest member
Vinay_Kumar Nevatia
Top