help using smptd

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Edward Elliott

    #1

    help using smptd

    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.SMTPServe r 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. BaseHTTPRequest Handler? 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.SMTPServ er):
    def process_message (self, peer, mailfrom, rcpttos, data):
    # my code here

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


    --
    Edward Elliott
    UC Berkeley School of Law (Boalt Hall)
    complangpython at eddeye dot net
  • Heiko Wundram

    #2
    Re: help using smptd

    Am Sonntag 14 Mai 2006 23:47 schrieb Dennis Lee Bieber:[color=blue]
    > On Sun, 14 May 2006 20:47:33 GMT, Edward Elliott <nobody@127.0.0 .1>
    >
    > declaimed the following in comp.lang.pytho n:[color=green]
    > > class SMTPProxy (smtpd.SMTPServ er):[/color]
    >
    > Don't you need to have an __init__() that invokes SMTPServer's
    > __init__()?[/color]

    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.

    Comment

    • Edward Elliott

      #3
      Re: help using smptd

      Heiko Wundram wrote:
      [color=blue]
      > 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.[/color]

      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.

      --
      Edward Elliott
      UC Berkeley School of Law (Boalt Hall)
      complangpython at eddeye dot net

      Comment

      • Edward Elliott

        #4
        Re: help using smptd

        Edward Elliott wrote:
        [color=blue]
        > import smtpd
        >
        > class SMTPProxy (smtpd.SMTPServ er):
        > def process_message (self, peer, mailfrom, rcpttos, data):
        > # my code here
        >
        > proxy = SMTPProxy (listen_addr, relay_addr)
        > # now what?[/color]

        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?

        --
        Edward Elliott
        UC Berkeley School of Law (Boalt Hall)
        complangpython at eddeye dot net

        Comment

        Working...