Bonzo: SMTP Server built on top of Tornado

John Bonham's sigil three intersecting circles

About

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

Travis CI status Coveralls status Latest PyPI version Number of PyPI downloads

Hello, world

Here is a simple “Hello, world” example SMTP server for Bonzo:

import tornado.ioloop
import bonzo.smtp


class Handler(bonzo.smtp.RequestHandler):

    def data(self):
        print(self.request.message)

application = bonzo.smtp.Application(Handler)

if __name__ == '__main__':
    application.listen(2525)
    tornado.ioloop.IOLoop.current().start()

Installation

You can to use pip to install Bonzo:

$ pip install bonzo

Or using last source:

$ pip install git+https://github.com/puentesarrin/bonzo.git

Documentation

Sphinx is needed to generate the documentation. Documentation can be generated by issuing the following commands:

$ cd docs
$ make html

Or simply:

$ python setup.py doc

Also, the current documentation can be found at ReadTheDocs.

License

Bonzo is available under the Apache License, Version 2.0.

Indices and tables

Note

Logo credits: Image created by Freakofnurture (Wikimedia user), released into the public domain (source).

Package Documentation

bonzo Package

Bonzo is a SMTP Server built on top of Tornado.

bonzo.__init__.get_version_string()[source]
bonzo.__init__.version = '0.1.2+'

Current version of Bonzo.

bonzo Modules

bonzo.server – Non-blocking SMTP server

bonzo.smtpRequestHandler and Application classes

bonzo.testing – Unit testing support for asynchronous code

bonzo.errors – SMTP exceptions for response to the client

SMTP exceptions for response to the client.

exception bonzo.errors.BadArguments(syntax)[source]

Bases: bonzo.errors.SMTPError

Used to return a 501 status code.

Parameters:syntax (string) – Syntax returned to the client.
exception bonzo.errors.BadSequence(message)[source]

Bases: bonzo.errors.SMTPError

Used to return a 503 status code.

Parameters:message (string) – Message to be written to the stream and to response to the client.
exception bonzo.errors.InternalConfusion[source]

Bases: bonzo.errors.SMTPError

Used to return a 451 status code.

exception bonzo.errors.NotImplementedCommand(command)[source]

Bases: bonzo.errors.SMTPError

Used to return a 502 status code.

Parameters:command (string) – Command not implemented for the server.
exception bonzo.errors.SMTPError(status_code, message, log_message=None, *args)[source]

Bases: exceptions.Exception

An exception that will turn into an SMTP error response.

Parameters:
  • status_code (int) – SMTP status code. For a status codes list, see: http://www.greenend.org.uk/rjk/tech/smtpreplies.html.
  • message (string) – Message to be written to the stream in order to response to the client.
  • log_message (string) – Message to be written to the log for this error. May contain %s-style placeholders, which will be filled in with remaining positional parameters.
exception bonzo.errors.UnrecognisedCommand[source]

Bases: bonzo.errors.SMTPError

Used to return a 500 status code.

Release Notes

Next Release

Very soon

New modules

  • The bonzo.smtp module provides a better way to handles messages, this module is created to support asynchronous code in the request callback.
  • The bonzo.errors module provides custom exceptions for writing error codes to the client.

bonzo.server

  • SMTPConnection is raising the new exceptions from the bonzo.errors module on its command_ methods.
  • Added SMTPRequest for manage the request arguments, an instance of this class is passed as argument to the request callback.
  • Request callback receives an instance of SMTPRequest now. The message can be found on the message attribute of the request.
  • Request callbacks should call to the finish() method in order to finish the request by sending a successfully message to the client.
  • Exceptions in request callbacks no longer silently pass, instead the server returns an internal confusion error (451) to the client and the exceptions are now logged for debugging.
  • MAIL command returns a 503 error when a HELO command was not previously received.

bonzo.testing

  • Added connect, read_response, send_mail, and close methods to the AsyncSMTPTestCase class. These methods are oriented for ease to create tests to the SMTP server.

Release Notes for Bonzo 0.1.2

February 04, 2014

  • bonzo.smtpserver module is renamed to bonzo.server. This is motivated to add (in the next version) a module called smtp containing tools for handling requests with asynchronous features, very similar to tornado.web.
  • Added Python 3 support.
  • Added Travis and Coveralls configuration (Issue #1). Thanks to Luis Mayta.

Release Notes for Bonzo 0.1.1

February 02, 2014

  • Fixed lack of tests by adding the test suite to cover the 0.1.0 version.
  • The release just fixes this bad software engineering.

New modules

  • The bonzo.testing module provides an interface to run asynchronous tests over a SMTPServer running on a random port.

Release Notes for Bonzo 0.1.0

August 21, 2013

  • Initial and simple version without tests.
  • A port of the Python smtpd module which uses asyncore.

Contributors