Skip to main content

Test SMTP/IMAP server for local integration testing

Project description

Localmail

For local people.

Localmail is an SMTP and IMAP server that stores all messages into a single in-memory mailbox. It is designed to be used to speed up running test suites on systems that send email, such as new account sign up emails with confirmation codes. It can also be used to test SMTP/IMAP client code.

Features:

  • Fast and robust IMAP/SMTP implementations, including multipart messages and unicode support.

  • Includes simple HTTP interface for reading messages, which is useful for checking html emails.

  • Compatible with python’s stdlib client, plus clients like mutt and thunderbird.

  • Authentication is supported but completely ignored, all message go in single mailbox.

  • Messages not persisted by default, and will be lost on shutdown. Optionally, you can log messages to disk in mbox format.

Missing features/TODO:

  • SSL support

WARNING: not a real SMTP/IMAP server - not for production usage.

Running localmail

twistd localmail

This will run localmail in the background, SMTP on port 2025 and IMAP on 2143, It will log to a file ./twistd.log. Use the -n option if you want to run in the foreground, like so.

twistd -n localmail

You can pass in arguments to control parameters.

twistd localmail --imap <port> --smtp <port> --http <port> --file localmail.mbox

You can have localmail use random ports if you like. The port numbers will be logged. TODO: enable writing random port numbers to a file.

twisted -n localmail --random

Embedding

If you want to embed localmail in another non-twisted program, such as test runner, do the following.

import threading
import localmail

thread = threading.Thread(
   target=localmail.run,
   args=(2025, 2143, 8880, 'localmail.mbox')
)
thread.start()

...

localmail.shutdown_thread(thread)

This will run the twisted reactor in a separate thread, and shut it down on exit.

If you want to use random ports, you can pass a callback that will have the ports the service is listening on.

import threading
import localmail

def report(smtp, imap, http):
    """do stuff with ports"""

thread = threading.Thread(
   target=localmail.run,
   args=(0, 0, 0, None, report)
)
thread.start()

History

0.4 (2015-08-14)

  • support for using random port numbers

  • available as a universal wheel, general packaging improvements

  • Simple HTTP interface for browsing mail (requires jinja2)

  • Support writing to mbox file

  • Fixed date to work with mutt, example muttrc included in package.

0.3 (2013-05-24)

  • Multipart message support [via Ed Jannoo]

  • IMAP UID support

  • Support python 2.6, 2.7 and pypy, tested via tox

0.2 (2012-11-13)

  • Initial public release

  • Basic SMTP/IMAP server

Credits

“localmail” is written and maintained by Simon Davy

Contributors

The following people contributed directly or indirectly to this project:

  • Ed Jannoo <ed@azordi.com>

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

localmail-0.4.0.tar.gz (24.6 kB view details)

Uploaded Source

Built Distribution

localmail-0.4.0-py2.py3-none-any.whl (15.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file localmail-0.4.0.tar.gz.

File metadata

  • Download URL: localmail-0.4.0.tar.gz
  • Upload date:
  • Size: 24.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for localmail-0.4.0.tar.gz
Algorithm Hash digest
SHA256 161ce75eef93a061992f65f8bab97eb376545666478d4c00166b66c69dbc680d
MD5 0cabcf6fd694828f855935cd121e22a7
BLAKE2b-256 4c1e6bb2ba9a406436fc75a7c811e4aa69a44968f0bae81342cd3cf6b45f6eea

See more details on using hashes here.

File details

Details for the file localmail-0.4.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for localmail-0.4.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 cbbf0b9ad3e1cf749c20343225898428d82557490cb8fe3a43ce6b3aa85cbabf
MD5 f4b2a22d951e598577a2c5bef8b554a2
BLAKE2b-256 1abca50ce38f6bd09daf1e5965bb1738ea4b25082aaaf0ecb5aee1bac5cb482c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page