SMTP Debugging Server in Python

Python’s built-in smtpd was a simple and usable mail server for testing purposes. A simple cli call such as:

python3 -m smtpd -n localhost:2525

was sufficient to receive your debugging emails. However, there are some problems currently piling up, which are ignored by the python devs. I recently stumbled over the following problem:

$ python3 -m smtpd -n localhost:2525
error: uncaptured python exception, closing channel <__main__.SMTPChannel connected ('::1', 57670, 0, 0) at 0x7ffa6b79b160> (<class 'TypeError'>:process_message() got an unexpected keyword argument 'mail_options' [/usr/lib64/python3.8/|read|83] [/usr/lib64/python3.8/|handle_read_event|420] [/usr/lib64/python3.8/|handle_read|171] [/usr/lib64/python3.8/|found_terminator|386])

The problem occurs for example when sending mails from django to the test server. Short searches reveal that this is a known problem, and there are announcements that smptd is going to be deprecated in favor of aoismtpd.


pip3 install aiosmtpd
python3 -m aiosmtpd -n -l localhost:2525

This does fix the problem.