Test SMTP/IMAP server for local integration testing
Project description
Localmail
Localmail is SMTP and IMAP server that writes/reads 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.
Authentication is supported but completely ignored, and all senders and receiver email addresses are treated the same. Messages are not persisted, and will be lost on shutdown.
- Limitations
no SSL support
WARNING: not a real SMTP/IMAP server - not for production usage.
Install
pip install localmail
Run
There are multiple ways to run 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> -l localmail.log
Alternatively, run via tac file:
twistd -y localmail.tac
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)) thread.start() ... localmail.shutdown_thread(thread)
This will run the twisted reactor in a separate thread, and shut it down on exit.
Development
- ::
python setup.py develop
Testing
The test suite is very simple, it uses the python stdlib imaplib and smtplib modules as clients, rather than twisted IMAP/SMTP, so it’s more integration tests rather than unit tests.
- ::
python setup.py test [-s localmail.tests.test_localmail.SomeTestCase.test_something]
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
File details
Details for the file localmail-0.3.tar.gz
.
File metadata
- Download URL: localmail-0.3.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa032b76e739855b3c3f2ddb4586d1410e29a9406c57b3b7fc738536d7d60778 |
|
MD5 | bea9731645cb7e28c0dae95afeab533f |
|
BLAKE2b-256 | fbc6144194a0ec2f42bc1d2fee32209e6deaf37cea7c406e92892db86bced141 |