本文整理汇总了Python中slimta.relay.smtp.client.SmtpRelayClient类的典型用法代码示例。如果您正苦于以下问题:Python SmtpRelayClient类的具体用法?Python SmtpRelayClient怎么用?Python SmtpRelayClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SmtpRelayClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_rcptto
def test_rcptto(self):
self.sock.sendall(b'RCPT TO:<recipient>\r\n')
self.sock.recv(IsA(int)).AndReturn(b'250 Ok\r\n')
self.mox.ReplayAll()
client = SmtpRelayClient('addr', self.queue, socket_creator=self._socket_creator)
client._connect()
client._rcptto('recipient')
示例2: test_rset
def test_rset(self):
self.sock.sendall(b'RSET\r\n')
self.sock.recv(IsA(int)).AndReturn(b'250 Ok\r\n')
self.mox.ReplayAll()
client = SmtpRelayClient('addr', self.queue, socket_creator=self._socket_creator)
client._connect()
client._rset()
示例3: test_connect_failure
def test_connect_failure(self):
def socket_creator(address):
raise socket_error(None, None)
self.mox.ReplayAll()
client = SmtpRelayClient('addr', self.queue, socket_creator=socket_creator)
with self.assertRaises(TransientRelayError):
client._connect()
示例4: test_run_multiple
def test_run_multiple(self):
result1 = AsyncResult()
result2 = AsyncResult()
env1 = Envelope('[email protected]', ['[email protected]'])
env1.parse(b'From: [email protected]\r\n\r\ntest test\r\n')
env2 = Envelope('[email protected]', ['[email protected]'])
env2.parse(b'From: [email protected]\r\n\r\ntest test\r\n')
queue = BlockingDeque()
queue.append((result1, env1))
queue.append((result2, env2))
self.sock.recv(IsA(int)).AndReturn(b'220 Welcome\r\n')
self.sock.sendall(b'EHLO test\r\n')
self.sock.recv(IsA(int)).AndReturn(b'250-Hello\r\n250 PIPELINING\r\n')
self.sock.sendall(b'MAIL FROM:<[email protected]>\r\nRCPT TO:<[email protected]>\r\nDATA\r\n')
self.sock.recv(IsA(int)).AndReturn(b'250 Ok\r\n250 Ok\r\n354 Go ahead\r\n')
self.sock.sendall(b'From: [email protected]\r\n\r\ntest test\r\n.\r\n')
self.sock.recv(IsA(int)).AndReturn(b'250 Ok\r\n')
self.sock.sendall(b'MAIL FROM:<[email protected]>\r\nRCPT TO:<[email protected]>\r\nDATA\r\n')
self.sock.recv(IsA(int)).AndReturn(b'250 Ok\r\n250 Ok\r\n354 Go ahead\r\n')
self.sock.sendall(b'From: [email protected]\r\n\r\ntest test\r\n.\r\n')
self.sock.recv(IsA(int)).AndReturn(b'250 Ok\r\n')
self.sock.sendall(b'QUIT\r\n')
self.sock.recv(IsA(int)).AndReturn(b'221 Goodbye\r\n')
self.sock.close()
self.mox.ReplayAll()
client = SmtpRelayClient('addr', queue, socket_creator=self._socket_creator, ehlo_as='test', idle_timeout=0.0)
client._run()
self.assertEqual({'[email protected]': Reply('250', 'Ok')}, result1.get_nowait())
self.assertEqual({'[email protected]': Reply('250', 'Ok')}, result2.get_nowait())
示例5: test_run_multiple
def test_run_multiple(self):
result1 = self.mox.CreateMock(AsyncResult)
result2 = self.mox.CreateMock(AsyncResult)
env1 = Envelope('[email protected]', ['[email protected]'])
env1.parse('From: [email protected]\r\n\r\ntest test\r\n')
env2 = Envelope('[email protected]', ['[email protected]'])
env2.parse('From: [email protected]\r\n\r\ntest test\r\n')
queue = BlockingDeque()
queue.append((result1, env1))
queue.append((result2, env2))
self.sock.recv(IsA(int)).AndReturn('220 Welcome\r\n')
self.sock.sendall('EHLO test\r\n')
self.sock.recv(IsA(int)).AndReturn('250-Hello\r\n250 PIPELINING\r\n')
self.sock.sendall('MAIL FROM:<[email protected]>\r\nRCPT TO:<[email protected]>\r\nDATA\r\n')
self.sock.recv(IsA(int)).AndReturn('250 Ok\r\n250 Ok\r\n354 Go ahead\r\n')
self.sock.sendall('From: [email protected]\r\n\r\ntest test\r\n.\r\n')
self.sock.recv(IsA(int)).AndReturn('250 Ok\r\n')
result1.set([None])
self.sock.sendall('MAIL FROM:<[email protected]>\r\nRCPT TO:<[email protected]>\r\nDATA\r\n')
self.sock.recv(IsA(int)).AndReturn('250 Ok\r\n250 Ok\r\n354 Go ahead\r\n')
self.sock.sendall('From: [email protected]\r\n\r\ntest test\r\n.\r\n')
self.sock.recv(IsA(int)).AndReturn('250 Ok\r\n')
result2.set([None])
self.sock.sendall('QUIT\r\n')
self.sock.recv(IsA(int)).AndReturn('221 Goodbye\r\n')
self.sock.close()
self.mox.ReplayAll()
client = SmtpRelayClient(None, queue, socket_creator=self._socket_creator, ehlo_as='test', idle_timeout=0.0)
client._run()
示例6: test_handshake_starttls
def test_handshake_starttls(self):
sock = self.mox.CreateMockAnything()
sock.fileno = lambda: -1
def socket_creator(address):
return sock
sock.recv(IsA(int)).AndReturn("220 Welcome\r\n")
sock.sendall("EHLO test\r\n")
sock.recv(IsA(int)).AndReturn("250-Hello\r\n250 STARTTLS\r\n")
sock.sendall("STARTTLS\r\n")
sock.recv(IsA(int)).AndReturn("220 Go ahead\r\n")
sock.tls_wrapper(sock, self.tls_args).AndReturn(sock)
sock.sendall("EHLO test\r\n")
sock.recv(IsA(int)).AndReturn("250 Hello\r\n")
self.mox.ReplayAll()
client = SmtpRelayClient(
None,
self.queue,
socket_creator=socket_creator,
tls=self.tls_args,
tls_wrapper=sock.tls_wrapper,
ehlo_as="test",
)
client._connect()
client._handshake()
示例7: test_disconnect
def test_disconnect(self):
self.sock.sendall("QUIT\r\n")
self.sock.recv(IsA(int)).AndReturn("221 Goodbye\r\n")
self.sock.close()
self.mox.ReplayAll()
client = SmtpRelayClient(None, self.queue, socket_creator=self._socket_creator, ehlo_as="test")
client._connect()
client._disconnect()
示例8: test_disconnect
def test_disconnect(self):
self.sock.sendall(b'QUIT\r\n')
self.sock.recv(IsA(int)).AndReturn(b'221 Goodbye\r\n')
self.sock.close()
self.mox.ReplayAll()
client = SmtpRelayClient('addr', self.queue, socket_creator=self._socket_creator, ehlo_as='test')
client._connect()
client._disconnect()
示例9: test_disconnect_failure
def test_disconnect_failure(self):
self.sock.sendall(b'QUIT\r\n')
self.sock.recv(IsA(int)).AndRaise(socket_error(None, None))
self.sock.close()
self.mox.ReplayAll()
client = SmtpRelayClient('addr', self.queue, socket_creator=self._socket_creator, ehlo_as='test')
client._connect()
client._disconnect()
示例10: test_handshake_tls_immediately
def test_handshake_tls_immediately(self):
tls_wrapper = self.mox.CreateMockAnything()
tls_wrapper(self.sock, self.tls_args).AndReturn(self.sock)
self.sock.recv(IsA(int)).AndReturn(b'220 Welcome\r\n')
self.sock.sendall(b'EHLO there\r\n')
self.sock.recv(IsA(int)).AndReturn(b'250 Hello\r\n')
self.mox.ReplayAll()
client = SmtpRelayClient('addr', self.queue, socket_creator=self._socket_creator, tls=self.tls_args, tls_wrapper=tls_wrapper, tls_immediately=True, ehlo_as='there')
client._connect()
client._handshake()
示例11: test_handshake_authenticate_badcreds
def test_handshake_authenticate_badcreds(self):
self.sock.recv(IsA(int)).AndReturn(b'220 Welcome\r\n')
self.sock.sendall(b'EHLO there\r\n')
self.sock.recv(IsA(int)).AndReturn(b'250-Hello\r\n250 AUTH PLAIN\r\n')
self.sock.sendall(b'AUTH PLAIN AHRlc3RAZXhhbXBsZS5jb20AcGFzc3dk\r\n')
self.sock.recv(IsA(int)).AndReturn(b'535 Nope!\r\n')
self.mox.ReplayAll()
client = SmtpRelayClient(('addr', 0), self.queue, socket_creator=self._socket_creator, credentials=('[email protected]', 'passwd'), ehlo_as='there', auth_mechanism=b'PLAIN')
client._connect()
with self.assertRaises(PermanentRelayError):
client._handshake()
示例12: test_run_nomessages
def test_run_nomessages(self):
queue = PriorityQueue()
self.sock.recv(IsA(int)).AndReturn('220 Welcome\r\n')
self.sock.sendall('EHLO test\r\n')
self.sock.recv(IsA(int)).AndReturn('250-Hello\r\n250 PIPELINING\r\n')
self.sock.sendall('QUIT\r\n')
self.sock.recv(IsA(int)).AndReturn('221 Goodbye\r\n')
self.sock.close()
self.mox.ReplayAll()
client = SmtpRelayClient(None, queue, socket_creator=self._socket_creator, ehlo_as='test', idle_timeout=0)
client._run()
示例13: test_handshake_tls_immediately
def test_handshake_tls_immediately(self):
sock = self.mox.CreateMockAnything()
sock.fileno = lambda: -1
def socket_creator(address):
return sock
sock.tls_wrapper(sock, self.tls_args).AndReturn(sock)
sock.recv(IsA(int)).AndReturn(b'220 Welcome\r\n')
sock.sendall(b'EHLO test\r\n')
sock.recv(IsA(int)).AndReturn(b'250 Hello\r\n')
self.mox.ReplayAll()
client = SmtpRelayClient('addr', self.queue, socket_creator=socket_creator, tls=self.tls_args, tls_wrapper=sock.tls_wrapper, tls_immediately=True, ehlo_as='test')
client._connect()
client._handshake()
示例14: test_handshake_authenticate
def test_handshake_authenticate(self):
sock = self.mox.CreateMockAnything()
sock.fileno = lambda: -1
def socket_creator(address):
return sock
sock.recv(IsA(int)).AndReturn(b'220 Welcome\r\n')
sock.sendall(b'EHLO test\r\n')
sock.recv(IsA(int)).AndReturn(b'250-Hello\r\n250 AUTH PLAIN\r\n')
sock.sendall(b'AUTH PLAIN AHRlc3RAZXhhbXBsZS5jb20AcGFzc3dk\r\n')
sock.recv(IsA(int)).AndReturn(b'235 Ok\r\n')
self.mox.ReplayAll()
client = SmtpRelayClient('addr', self.queue, socket_creator=socket_creator, credentials=('[email protected]', 'passwd'), ehlo_as='test')
client._connect()
client._handshake()
示例15: test_run_banner_failure
def test_run_banner_failure(self):
result = self.mox.CreateMock(AsyncResult)
env = Envelope('[email protected]', ['[email protected]'])
env.parse('From: [email protected]\r\n\r\ntest test\r\n')
queue = BlockingDeque()
queue.append((result, env))
self.sock.recv(IsA(int)).AndReturn('520 Not Welcome\r\n')
result.set_exception(IsA(PermanentRelayError))
self.sock.sendall('QUIT\r\n')
self.sock.recv(IsA(int)).AndReturn('221 Goodbye\r\n')
self.sock.close()
self.mox.ReplayAll()
client = SmtpRelayClient(None, queue, socket_creator=self._socket_creator, ehlo_as='test')
client._run()