This library is based on now-discontinued smtpd module from the Python 3.11 standard
library. The original module and its tests are licensed under Python Software
Foundation License Version 2.
The modifications and new code is licensed under the BSD-3-Clause license.
- Updated to run using socketserver
instead of
asyncoreandasynchat - Removed CLI
- Removed DebuggingProxy and PureProxy classes
- Removed the
decode_dataconstructor argument (always disabled) - Removed the
enable_SMTPUTF8constructor argument (always enabled) - Added type annotations
pip install minismtpd
import signal
from minismtpd import SMTPServer
class MyServer(SMTPServer):
def process_message(self, peer, mailfrom, rcpttos, data):
print(f"Peer: {peer}")
print(f"Mail from: {mailfrom}")
print(f"Rcpt To: {rcpttos}")
print(f"Data: {data}")
with MyServer(("localhost", 2525)) as server:
print("Listening on localhost:2525 ...")
def on_signal(signum, frame):
print("Shutting down...")
server.shutdown()
# Run until Ctrl-C
signal.signal(signal.SIGINT, on_signal)
server.serve_forever()