[Twisted-web] HTTP POST from SMTP server

Jean-Paul Calderone exarkun at divmod.com
Sat Dec 8 18:02:15 EST 2007

On Sat, 8 Dec 2007 22:54:45 +0000, James Brady <rent.lupin.road at gmail.com> wrote:
>Hi all,
>I'm a complete Twisted newcomer, so still getting to grips with the ways
>thing work..
>What I'm trying to do is submit a POST request when I receive email into my
>SMTP server.
>At the moment, I've basically modified emailserver.tac from the examples (
>My eomReceived message has this code added to it:
>        client = getPage(url='http://localhost:8080/message_event_notify',
>            postdata=urlencode(postdata),
>            headers={ 'Content-Type': 'application/x-www-form-urlencoded' }
>        client.addCallback(self.success)
>        client.addErrback(self.failure)
>        reactor.run()

You don't need to call reactor.run() here - the reactor is already running
(that's how the SMTP server works, after all).  In fact, you can't call
reactor.run() here - the reactor mainloop is not reentrant.

Instead, you probably want to return the "client" Deferred from eomReceived.
The SMTP protocol code will use that Deferred to know when to indicate to
the SMTP client which is talking to it when the message has been delivered
successful or if there is an error.


More information about the Twisted-web mailing list