[Twisted-Python] SMTP server
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? best regards, Jan -- "It is an illusion to think that we are free to apply our increasing knowledge in any way we choose. In reality we are struggling to deal with the consequences of it." -- John Gray ---- Electronic Technology Coordinator Information/Communication/Technology Greenpeace International Ottho Heldringstraat 5 1066 AZ AMSTERDAM Netherlands (MET) direct +31 (0)20 7182084 fax +31 (0)20 5148151 reception +31 (0)20 5148150 email jan.bakuwel&int.greenpeace.org private jan.bakuwel&hccnet.nl (replace & by @ in the emailaddress)
On Thu, 09 Nov 2006 13:44:55 +0100, Jan Bakuwel <jan.bakuwel@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
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). Are you suggesting that I would implement my own version of IMessageDelivery to include the abstract method I'm wishing for? Just
Hi Jean-Paul, trying to understand what you're suggesting... :-) regards, Jan -- "It is an illusion to think that we are free to apply our increasing knowledge in any way we choose. In reality we are struggling to deal with the consequences of it." -- John Gray ---- Electronic Technology Coordinator Information/Communication/Technology Greenpeace International Ottho Heldringstraat 5 1066 AZ AMSTERDAM Netherlands (MET) direct +31 (0)20 7182084 fax +31 (0)20 5148151 reception +31 (0)20 5148150 email jan.bakuwel&int.greenpeace.org private jan.bakuwel&hccnet.nl (replace & by @ in the emailaddress)
On Fri, 10 Nov 2006 10:57:31 +0100, Jan Bakuwel <jan.bakuwel@int.greenpeace.org> wrote:
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). Are you suggesting that I would implement my own version of IMessageDelivery to include the abstract method I'm wishing for? Just
Hi Jean-Paul, trying to understand what you're suggesting... :-)
You should implement IMessageDelivery and your implementation should keep internal state which tracks which users the message should be delivered to. This state should be transferred to the IMessage provider which validateTo returns. When IMessage.messageDone is called, you should use that state to deliver the message once and only once to the intended recipients. IMessage.messageDone is the notification you want, as long as you are using a different IMessageDelivery for each message, which is what implementing IMessageDeliveryFactory lets you do. Jean-Paul
participants (2)
-
Jan Bakuwel
-
Jean-Paul Calderone