def __init__(self, host, port): self._tmp_dir = TemporaryDirectory() super().__init__(handler=Mailbox( os.path.join(self._tmp_dir.name, 'mailbox')), hostname=host, port=port, ready_timeout=2.0)
def setUp(self): self.tempdir = TemporaryDirectory() self.addCleanup(self.tempdir.cleanup) self.maildir_path = os.path.join(self.tempdir.name, 'maildir') self.handler = handler = Mailbox(self.maildir_path) controller = Controller(handler) controller.start() self.addCleanup(controller.stop) self.address = (controller.hostname, controller.port)
def mailbox_controller(temp_maildir, get_controller) -> Generator[Controller, None, None]: handler = Mailbox(temp_maildir) controller = get_controller(handler) controller.start() Global.set_addr_from(controller) # yield controller # controller.stop()
def generate_email_server(tmpdir): """ This starts an SMTP server in a new thread, which listens on port 9487. STARTTLS is enabled using a self-signed certificate. """ if not isinstance(tmpdir, py.path.local): tmpdir = py.path.local(tmpdir) cert_file, key_file = generate_cert_and_key(tmpdir) ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) ctx.load_cert_chain(cert_file, keyfile=key_file) maildir = str(tmpdir.join("maildir")) controller = STARTTLSController( Mailbox(maildir), hostname="localhost", port=9487, ssl_context=ctx ) return controller, maildir