Python smtpd.SMTPServer() Examples

The following are 30 code examples of smtpd.SMTPServer(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module smtpd , or try the search function .
Example #1
Source File: tests.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        threading.Thread.__init__(self)
        # New kwarg added in Python 3.5; default switching to False in 3.6.
        # Setting a value only silences a deprecation warning in Python 3.5.
        kwargs['decode_data'] = True
        smtpd.SMTPServer.__init__(self, *args, **kwargs)
        self._sink = []
        self.active = False
        self.active_lock = threading.Lock()
        self.sink_lock = threading.Lock() 
Example #2
Source File: test_smtplib.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kw):
        self._extra_features = []
        smtpd.SMTPServer.__init__(self, *args, **kw) 
Example #3
Source File: test_smtplib.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kw):
        # The base SMTP server turns these on automatically, but our test
        # server is set up to munge the EHLO response, so we need to provide
        # them as well.  And yes, the call is to SMTPServer not SimSMTPServer.
        self._extra_features = ['SMTPUTF8', '8BITMIME']
        smtpd.SMTPServer.__init__(self, *args, **kw) 
Example #4
Source File: test_smtpd.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        smtpd.SMTPServer.__init__(self, *args, **kwargs)
        self.messages = []
        if self._decode_data:
            self.return_status = 'return status'
        else:
            self.return_status = b'return status' 
Example #5
Source File: test_smtpd.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def test_process_message_unimplemented(self):
        server = smtpd.SMTPServer((support.HOST, 0), ('b', 0),
                                  decode_data=True)
        conn, addr = server.accept()
        channel = smtpd.SMTPChannel(server, conn, addr, decode_data=True)

        def write_line(line):
            channel.socket.queue_recv(line)
            channel.handle_read()

        write_line(b'HELO example')
        write_line(b'MAIL From:eggs@example')
        write_line(b'RCPT To:spam@example')
        write_line(b'DATA')
        self.assertRaises(NotImplementedError, write_line, b'spam\r\n.\r\n') 
Example #6
Source File: test_smtpd.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def test_decode_data_default_warns(self):
        with self.assertWarns(DeprecationWarning):
            smtpd.SMTPServer((support.HOST, 0), ('b', 0)) 
Example #7
Source File: test_smtpd.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def test_socket_uses_IPv6(self):
        server = smtpd.SMTPServer((support.HOSTv6, 0), (support.HOST, 0),
                                  decode_data=False)
        self.assertEqual(server.socket.family, socket.AF_INET6) 
Example #8
Source File: test_smtpd.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def test_socket_uses_IPv4(self):
        server = smtpd.SMTPServer((support.HOST, 0), (support.HOSTv6, 0),
                                  decode_data=False)
        self.assertEqual(server.socket.family, socket.AF_INET) 
Example #9
Source File: test_logging.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, addr, handler, poll_interval, sockmap):
            smtpd.SMTPServer.__init__(self, addr, None, map=sockmap,
                                      decode_data=True)
            self.port = self.socket.getsockname()[1]
            self._handler = handler
            self._thread = None
            self.poll_interval = poll_interval 
Example #10
Source File: test_smtplib.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kw):
        self._extra_features = []
        smtpd.SMTPServer.__init__(self, *args, **kw) 
Example #11
Source File: test_smtplib.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self, *args, **kw):
        self._extra_features = []
        smtpd.SMTPServer.__init__(self, *args, **kw) 
Example #12
Source File: tests.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        threading.Thread.__init__(self)
        # New kwarg added in Python 3.5; default switching to False in 3.6.
        # Setting a value only silences a deprecation warning in Python 3.5.
        kwargs['decode_data'] = True
        smtpd.SMTPServer.__init__(self, *args, **kwargs)
        self._sink = []
        self.active = False
        self.active_lock = threading.Lock()
        self.sink_lock = threading.Lock() 
Example #13
Source File: test_smtplib.py    From android_universal with MIT License 5 votes vote down vote up
def __init__(self, *args, **kw):
        self._extra_features = []
        self._addresses = {}
        smtpd.SMTPServer.__init__(self, *args, **kw) 
Example #14
Source File: test_smtplib.py    From android_universal with MIT License 5 votes vote down vote up
def __init__(self, *args, **kw):
        # The base SMTP server turns these on automatically, but our test
        # server is set up to munge the EHLO response, so we need to provide
        # them as well.  And yes, the call is to SMTPServer not SimSMTPServer.
        self._extra_features = ['SMTPUTF8', '8BITMIME']
        smtpd.SMTPServer.__init__(self, *args, **kw) 
Example #15
Source File: test_smtpd.py    From android_universal with MIT License 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        smtpd.SMTPServer.__init__(self, *args, **kwargs)
        self.messages = []
        if self._decode_data:
            self.return_status = 'return status'
        else:
            self.return_status = b'return status' 
Example #16
Source File: test_smtpd.py    From android_universal with MIT License 5 votes vote down vote up
def test_process_message_unimplemented(self):
        server = smtpd.SMTPServer((support.HOST, 0), ('b', 0),
                                  decode_data=True)
        conn, addr = server.accept()
        channel = smtpd.SMTPChannel(server, conn, addr, decode_data=True)

        def write_line(line):
            channel.socket.queue_recv(line)
            channel.handle_read()

        write_line(b'HELO example')
        write_line(b'MAIL From:eggs@example')
        write_line(b'RCPT To:spam@example')
        write_line(b'DATA')
        self.assertRaises(NotImplementedError, write_line, b'spam\r\n.\r\n') 
Example #17
Source File: test_smtpd.py    From android_universal with MIT License 5 votes vote down vote up
def test_decode_data_and_enable_SMTPUTF8_raises(self):
        self.assertRaises(
            ValueError,
            smtpd.SMTPServer,
            (support.HOST, 0),
            ('b', 0),
            enable_SMTPUTF8=True,
            decode_data=True) 
Example #18
Source File: test_smtpd.py    From android_universal with MIT License 5 votes vote down vote up
def test_socket_uses_IPv4(self):
        server = smtpd.SMTPServer((support.HOSTv4, 0), (support.HOSTv6, 0))
        self.assertEqual(server.socket.family, socket.AF_INET) 
Example #19
Source File: server_tests.py    From personfinder with Apache License 2.0 5 votes vote down vote up
def run(self):
        class MailServer(smtpd.SMTPServer):
            def process_message(self, peer, mailfrom, rcpttos, data):
                print('mail from:', mailfrom, 'to:', rcpttos, file=sys.stderr)
                MailThread.messages.append(
                    {'from': mailfrom, 'to': rcpttos, 'data': data})

        try:
            server = MailServer(('localhost', self.port), None)
        except Exception, e:
            print('SMTP server failed: %s' % e, file=sys.stderr)
            sys.exit(-1) 
Example #20
Source File: test_smtplib.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kw):
        self._extra_features = []
        smtpd.SMTPServer.__init__(self, *args, **kw) 
Example #21
Source File: smtpd_mock.py    From integration with Apache License 2.0 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        self.messages = []
        smtpd.SMTPServer.__init__(self, *args, **kwargs) 
Example #22
Source File: __init__.py    From script-languages with MIT License 5 votes vote down vote up
def __init__(self, debug=False, esmtp=True):
        super(SMTPServer, self).__init__()
        self.esmtp = esmtp
        self.debug = debug
        self._server = None
        self._wait_for_server = threading.Semaphore(0) 
Example #23
Source File: __init__.py    From script-languages with MIT License 5 votes vote down vote up
def stop(self):
        self._server.close()
        super(SMTPServer, self).stop() 
Example #24
Source File: test_smtplib.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kw):
        self._extra_features = []
        smtpd.SMTPServer.__init__(self, *args, **kw) 
Example #25
Source File: test_smtplib.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kw):
        # The base SMTP server turns these on automatically, but our test
        # server is set up to munge the EHLO response, so we need to provide
        # them as well.  And yes, the call is to SMTPServer not SimSMTPServer.
        self._extra_features = ['SMTPUTF8', '8BITMIME']
        smtpd.SMTPServer.__init__(self, *args, **kw) 
Example #26
Source File: test_smtpd.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        smtpd.SMTPServer.__init__(self, *args, **kwargs)
        self.messages = []
        if self._decode_data:
            self.return_status = 'return status'
        else:
            self.return_status = b'return status' 
Example #27
Source File: test_smtpd.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def test_process_message_unimplemented(self):
        server = smtpd.SMTPServer((support.HOST, 0), ('b', 0),
                                  decode_data=True)
        conn, addr = server.accept()
        channel = smtpd.SMTPChannel(server, conn, addr, decode_data=True)

        def write_line(line):
            channel.socket.queue_recv(line)
            channel.handle_read()

        write_line(b'HELO example')
        write_line(b'MAIL From:eggs@example')
        write_line(b'RCPT To:spam@example')
        write_line(b'DATA')
        self.assertRaises(NotImplementedError, write_line, b'spam\r\n.\r\n') 
Example #28
Source File: test_smtpd.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def test_decode_data_default_warns(self):
        with self.assertWarns(DeprecationWarning):
            smtpd.SMTPServer((support.HOST, 0), ('b', 0)) 
Example #29
Source File: test_smtpd.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def test_socket_uses_IPv6(self):
        server = smtpd.SMTPServer((support.HOSTv6, 0), (support.HOST, 0),
                                  decode_data=False)
        self.assertEqual(server.socket.family, socket.AF_INET6) 
Example #30
Source File: test_smtpd.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def test_socket_uses_IPv4(self):
        server = smtpd.SMTPServer((support.HOST, 0), (support.HOSTv6, 0),
                                  decode_data=False)
        self.assertEqual(server.socket.family, socket.AF_INET)