def _listenServer(self, d): from twisted.internet.protocol import Factory from twisted.internet import reactor f = Factory() f.onConnectionLost = d f.protocol = FakeSMTPServer return reactor.listenTCP(SMTP_SERVER_PORT, f)