import socket import ssl from smtpd import SMTPServer import asyncore server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_socket.bind(('localhost', 587)) server_socket.listen(1) context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) context.load_cert_chain(certfile="server.crt", keyfile="server.key") class MySMTPServer(SMTPServer): def process_message(self, peer, mailfrom, rcpttos, data, mail_options=None, rcpt_options=None): print(data) return server = MySMTPServer(("89.179.126.189", 1080), None) asyncore.loop() while True: print("Accepting") client_socket, addr = server_socket.accept() ssl_socket = context.wrap_socket(client_socket, server_side=True) print("Wrapped") ssl_socket.settimeout(10) data = ssl_socket.recv() print(data) print("Data Received") ssl_socket.close()