Python SMTP Servers and Clients - Python 3.5 - Python 2.7

SMTP Server Examples

SMTP Server Implementations

Twisted Mail

Twisted Mail contains high-level, efficient protocol implementations for both clients and servers of SMTP, POP3, and IMAP4. Additionally, it contains an "out of the box" combination SMTP/POP3 virtual-hosting mail server. Also included is a read/write Maildir implementation and a basic Mail Exchange calculator (depends on Twisted Names).

See PythonTwisted


Bonzo is a Python SMTP Server using the asynchronous network library of PythonTornado. And it’s actually a port of Python’s smtpd module.


pymta is a library to build a custom SMTP server in Python


pytma uses multiple processes to handle more than one connection at the same time. In order to do this in a platform-independent manner, it utilizes the multiprocessing module.

The basic SMTP program flow is determined by two state machines: One for the SMTP command parsing mode (single-line commands or data) in the SMTPCommandParser and another much bigger state machine in the SMTPSession to control the correct order of commands sent by the SMTP client.

The PythonMTA is the main server component which listens on a certain port for new connections. There should be only one instance of this object. When a new connection is received, the PythonMTA spawns WorkerProcess? (if you have the multiprocessing module installed) which triggers a SMTPCommand parser that handles all the SMTP communitcation. When a message was submitted successfully, the new_message_accepted() method of your IMessageDeliverer will be called so it is in charge of actually doing something with the message.

You can instantiate a new server like that:

from pymta import PythonMTA, BlackholeDeliverer

if __name__ == '__main__':
    # SMTP server will listen on localhost/port 8025
    server = PythonMTA('localhost', 8025, BlackholeDeliverer())



Getting old ... 2013 ?

Last modified 4 years ago Last modified on 02/12/2015 03:48:13 PM