Smtpd server python

From UVOO Tech Wiki
Revision as of 20:52, 8 April 2024 by Busk (talk | contribs) (Created page with "``` import asyncore from smtpd import SMTPServer class MySMTPServer(SMTPServer): def process_message(self, peer, mailfrom, rcpttos, data): print(f"Received messa...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
import asyncore
from smtpd import SMTPServer


class MySMTPServer(SMTPServer):
    def process_message(self, peer, mailfrom, rcpttos, data):
        print(f"Received message from: {mailfrom}")
        print(f"Recipients: {rcpttos}")
        print("Message:")
        print(data)


def run_server():
    # Replace 'localhost' and 1025 with the desired hostname and port
    server = MySMTPServer(('localhost', 1025), None)
    print("SMTP echo server running...")
    try:
        asyncore.loop()
    except KeyboardInterrupt:
        print("Server stopped.")


if __name__ == "__main__":
    run_server()