def setUp(self): """ Create an ESMTP instance attached to a StringTransport. """ self.server = smtp.ESMTP({'LOGIN': imap4.LOGINCredentials}) self.server.host = 'localhost' self.transport = StringTransport( peerAddress=address.IPv4Address('TCP', '127.0.0.1', 12345)) self.server.makeConnection(self.transport)
def testESMTPGreetingExtended(self): """ Test that the string "ESMTP" does appear in the ESMTP server's greeting since L{smtp.ESMTP} does support the SMTP extensions which that advertises to the client. """ s = smtp.ESMTP() t = StringTransport() s.makeConnection(t) s.connectionLost(error.ConnectionDone()) self.assertIn("ESMTP", t.value())
def test_send_email(self): """Happy-path test that we can send email to a non-TLS server.""" h = self.hs.get_send_email_handler() d = ensureDeferred( h.send_email("*****@*****.**", "test subject", "Tests", "HTML content", "Text content")) # there should be an attempt to connect to localhost:25 self.assertEqual(len(self.reactor.tcpClients), 1) (host, port, client_factory, _timeout, _bindAddress) = self.reactor.tcpClients[0] self.assertEqual(host, "localhost") self.assertEqual(port, 25) # wire it up to an SMTP server message_delivery = _DummyMessageDelivery() server_protocol = smtp.ESMTP() server_protocol.delivery = message_delivery # make sure that the server uses the test reactor to set timeouts server_protocol.callLater = self.reactor.callLater # type: ignore[assignment] client_protocol = client_factory.buildProtocol(None) client_protocol.makeConnection( FakeTransport(server_protocol, self.reactor)) server_protocol.makeConnection( FakeTransport( client_protocol, self.reactor, peer_address=IPv4Address("TCP", "127.0.0.1", 1234), )) # the message should now get delivered self.get_success(d, by=0.1) # check it arrived self.assertEqual(len(message_delivery.messages), 1) user, msg = message_delivery.messages.pop() self.assertEqual(str(user), "*****@*****.**") self.assertIn(b"Subject: test subject", msg)
def buildProtocol(self, addr): proto = smtp.ESMTP() proto.delivery = StdoutMessageDelivery(proto) return proto
def buildProtocol(self, addr): proto = smtp.ESMTP() proto.delivery = LocalMessageDelivery(proto, self.baseDir) return proto