[Twisted-Python] Do Twisted support LMTP servers?

Simon Hedberg simon at hedberg.net
Thu Apr 20 08:32:11 EDT 2006

Jesus Cea wrote:
> Hash: SHA1
> Simon Hedberg wrote:
>> I have been looking at ways to have postfix talking to my twisted app
>> and today tried LMTP successfully for the first time. What I've done
>> so far is just subclass the ESMTP protocol and add do_LHLO which
>> seems to do the trick for some basic usage at least. Looking at
>> http://www.ietf.org/rfc/rfc2033.txt it seems like it shouldn't be to
>> hard to make a proper LMTP implementation. Perhaps someone more
>> familiar with twisted.mail could have a look.
> Your mini LMTP implementation fails if a message is sent to several
> recipients, since LMTP must answer with a status code per
> destination. That is the main difference with SMTP.  
> But good starting point :)
> Hope "somebody" takes the token and complete a RFC compliant
> implementation... :-p 
> - --

Ok, I had a closer look and here's a more complete version, that sends a
status code for each recipient. 
Try it out

class LMTP(smtp.ESMTP):
    def do_LHLO(self, rest):
        peer = self.transport.getPeer()
            host = peer.host
        except AttributeError:
            host = str(peer)
        self._helo = (rest, host)
        self._from = None
        self._to = []
        self.sendCode(250, '%s Hello %s, nice to meet you\n%s' %
(self.host, host,self.listExtensions()))

    def do_HELO(self,rest):
        return self.do_UNKNOWN(self,rest)
    def do_EHLO(self,rest):
        return self.do_UNKNOWN(self,rest)
    def _messageHandled(self, resultList):
        for (success, result) in resultList:
            if success:
                self.sendCode(250, 'OK')
                code = 550
                msg = 'Could not deliver e-mail'
                smtperr = result.check(smtp.SMTPClientError)
                if smtperr:
                    code = result.value.code
                    msg  = result.value.resp
                self.sendCode(code, msg)

More information about the Twisted-Python mailing list