Difference between revisions of "Smtpd server python"
Jump to navigation
Jump to search
(Created page with "``` import asyncore from smtpd import SMTPServer class MySMTPServer(SMTPServer): def process_message(self, peer, mailfrom, rcpttos, data): print(f"Received messa...") |
(No difference)
|
Latest revision as of 20:52, 8 April 2024
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()