all Python 3until 3.12Removed from the standard libraryterm
smtpd
removed modules
Module with a simple asyncore-based SMTP server for receiving mail. Removed in Python 3.12; use the aiosmtpd package or your own asyncio server.
Syntax
import smtpd # до 3.12
smtpd provided SMTPServer and DebuggingServer: python -m smtpd -n -c DebuggingServer started a server that printed incoming mail, handy for testing outgoing email. The module was built on asyncore and was deprecated with it in Python 3.6 and removed in 3.12 under PEP 594. How to rewrite: for mail tests use the third-party aiosmtpd package (python -m aiosmtpd -n is the same debugging server), maintained outside the standard library. If you need a minimal server of your own, write it with asyncio: asyncio.start_server() and line-by-line command parsing with reader.readline(). Sending mail is still smtplib.
Examples
# Python 3.12+
try:
import smtpd
except ModuleNotFoundError as e:
print(type(e).__name__) # → ModuleNotFoundError
# Python 3.12+
import asyncio, socket
async def handle(reader, writer):
writer.write(b'220 ready\r\n')
line = await reader.readline()
if line.startswith(b'HELO'):
writer.write(b'250 hello\r\n')
await writer.drain()
writer.close()
async def main():
a, b = socket.socketpair()
server_side = await asyncio.open_connection(sock=a)
reader, writer = await asyncio.open_connection(sock=b)
task = asyncio.create_task(handle(*server_side))
print(await reader.readline()) # → b'220 ready\r\n'
writer.write(b'HELO me\r\n')
print(await reader.readline()) # → b'250 hello\r\n'
await task
writer.close()
asyncio.run(main())
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy