Newbie: trying to twist my head around twisted (and python)

Jean-Paul Calderone exarkun at
Wed Oct 11 17:25:36 CEST 2006

On Wed, 11 Oct 2006 17:15:09 +0200, Jan Bakuwel <jan.bakuwel at> wrote:
>Hoi all,
>Please see below a small piece of python code that resembles a
>smtpserver using the twisted framework. The code is based on the example
>smtp server discussed in Twisted Network Programming Essentials.
>The unmodified example code can be found on the O'Reilly website:
>(, in ch08 subdir).
>I've removed all the code I don't (the original example write an email
>received with SMTP to a Maildir; I'll do something else with it). For
>the sake of the example, the only thing I'll do in eomReceived is print
>whether the message had any attachments or not, then return a "failed"
>if a message had any attachments and a "success" if not.
>According to the book, I need to return a "Deferred result" from the
>function eomReceived (see ???????? below).
>In eomReceived, I intend to process the email then either return success
> or failure. I've been looking at the twisted way of using twisted :-).
>According to the book "its a little confusing for a start" and I have to
>agree :-)

The return value of eomReceived is used to determine whether to signal to
the SMTP client whether the message has been accepted.  Regardless of your
application logic, if you are taking responsibility for the message, you
should return a successful result.  If all of your processing is synchronous,
then you simply need to return twisted.internet.defer.succeed(None) at the
end of the function.  If you have asynchronous processing to do (it does not
appear as though you do), you will need to return a Deferred which only fires
once that processing has been completed.


More information about the Python-list mailing list