[Twisted-Python] Mail content filter: How to avoid SMTP client finishing sending message before SMTP server finishes receiving it?

Jack Bates jack.bates at gmail.com
Sat Dec 11 20:05:08 MST 2010

Struggling little bit to write a Postfix content filter [1] with Twisted
Mail. The content filter will eventually add a cookie to the "from"
address, identifying the address that the message was sent to

Here's my attempt so far [2]

The problem is that the SMTP client finishes sending the message before
the SMTP server finishes receiving it - i.e. Client.sentMail() is called
before Message.eomReceived()

To fix this, I want SMTPClient.smtpState_data() [3], which uses
FileSender [4], to wait for the server to finish receiving the message
before proceeding to smtpState_msgSent()

Is this possible?

The only alternative I can think of is to not start sending the message
until after the server finishes receiving it - i.e. start sending the
message after Message.eomReceived() is called. But this seems to me like
it would have worse performance than sending messages at the same time
as they're being received - especially for a message with a large

How can I avoid the client finishing sending the message before the
server finishes receiving it?

[1] http://www.postfix.org/SMTPD_PROXY_README.html
[2] https://github.com/jablko/cookie/blob/master/cookie
[3] http://twistedmatrix.com/trac/browser/tags/releases/twisted-10.2.0/twisted/mail/smtp.py#L1126
[4] http://twistedmatrix.com/documents/current/api/twisted.protocols.basic.FileSender.html

More information about the Twisted-Python mailing list