[Twisted-Python] SMTP server

Jean-Paul Calderone exarkun at divmod.com
Thu Nov 9 09:05:21 MST 2006


On Thu, 09 Nov 2006 13:44:55 +0100, Jan Bakuwel <jan.bakuwel at int.greenpeace.org> wrote:
>Hoi all,
>
>This is my first message to the list so I think its appropriate to
>express my appreciation for all the excellent work done by the people
>who created & contributed to the twisted libraries.
>
>I have a small but interesting problem that I'd like to ask your advise
>on, please see the description below. If you notice that I haven't
>understood something properly, I hope you'll correct me :-)
>
>I've implemented a SMTP server (I've called it "xsmtp") using the
>twisted & python libraries. A MTA (Postfix) delivers email messages to
>the xsmtp server: the MTA opens a single SMTP session to the xsmpt
>server, then multiple "RCPT TO"s follow, one for each recipient.
>
>As a result The "validateFrom" procedure is called by the twisted
>library once, followed by multiple calls to the "validateTo" procedure.
>
>This is creating a small problem for me. Since I must process the email
>in the validateTo procedure, I will now receive multiple copies of the
>same email (albeit for different recipients). One of the tasks of the
>xsmtp server is to transmit these emails to another xsmtp server (SMTP
>cannot be used due to the inherently high latency connection between the
>two). Ideally I do not transfer the same email twice but would like to
>leave the delivery to multiple recipients up to the MTA on the other
>end. In a schema:
>
>-> MTA -> xsmtp -- high latency link --> xsmtp -> MTA -> local delivery
>
>To implement smtp.IMessageDelivery I have to provide for the following
>procedures:
>
>validateFrom:    called once shortly after SMTP session is initiated
>receivedHeader:  called multiple times for each recipient
>validateTo:      called multiple tiems for each recipient
>
>One could say that "validateFrom" is the start of the process (of
>receiving an email) "receivedHeader/validateTo" is the core of the
>process. What I am missing is something that indicates the end of the
>process.
>
>
>It would help me tremendously if smtp.IMessageDelivery would also
>provide an abstract method that is called once the message delivery is
>completed.
>
>Any suggestions, thoughts are very welcome; perhaps this is already
>possible with the twisted libraries in a different way as I'm suggesting
>here?

The situation is not ideal, but I think if you use IMessageDeliveryFactory
instead of IMessageDelivery you'll be able to accomplish your goal.

With IMessageDeliveryFactory, you can create a new IMessageDelivery provider
for each SMTP transaction.  validateTo is still called multiple times on
your IMessageDelivery provider, but because a new one is created for each
transaction, you should be able to avoid making multiple deliveries to your
real backend.

(As I wrote that I realized it was not a very clear explanation at all, but
I cannot think of another way to put it without actually implementing
something).

Jean-Paul




More information about the Twisted-Python mailing list