A small smtp server fixture for use with pytest that implements encryption and authentication to mimic a production SMTP server.
Reason this release was yanked:
Replaced by smtpdfix
Project description
pytest SMTPD Fixture
Not yet uploaded to PyPi. Version 0.2.1 coming soon.
As simple SMTP server based on aiosmtpd
for use as a fixture with pytest that supports encryption and authentication. All this does is receives messages and appends them to a list as an email.Message
.
Installing
Installing handled through PyPi:
pip install bebleo-smtpd-fixture
Or, can equally be included in a setup.py
file:
setup(
...
tests_require = [
"pytest",
"bebleo-smtpd-fixture",
],
)
Using
To use the smtpd
fixture import it into your conftest.py
file and then use it like any other pytest fixture. for example:
# conftest.py
from smtplib import SMTP
from bebleo_smtpd_fixture import smtpd
And then in the test:
# test_mail.py
def test_sendmail(smtpd):
from_addr = "from.addr@example.org"
to_addrs = "to.addr@example.org"
msg = f"From: {from_addr}\r\nTo: {to_addrs}\r\nSubject: Foo\r\n\r\nFoo bar"
with SMTP(smtpd.hostname, smtpd.port) as client:
client.sendmail(from_addr, to_addrs, msg)
assert len(smtpd.messages) == 1
Configuration
Configuration can be handled through environment variables:
Variable | Default | Description |
---|---|---|
SMTPD_HOST |
127.0.0.1 |
The hostname that the fixture will listen on. |
SMTPD_PORT |
8025 |
The port that the fixture will listen on. |
SMPTD_USERNAME |
user |
|
SMTPD_PASSWORD |
password |
|
SMTPD_USE_SSL |
False |
Whether the fixture should use fixed TLS/SSL for transactions |
SMTPD_USE_STARTTLS |
False |
Whether the fixture should use StartTLS to encrypt the connections. If using smptlib requires that the SMTP.starttls() be called before other commands are issued. |
Known Issues
- Firewalls may interfere with the operation of the smtp server.
- Server will accept messages even if the client is not authenticated. Issue #5
- Currently no support for termination through signals. Issue #4
Written 2020 with :coffee: and :heart: in Montreal, QC
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for bebleo-smtpd-fixture-0.2.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f6007996db961312d91a4208e7ee907337c186c456babd1faff6bde37bf0cfd |
|
MD5 | efd1cdf7487a505a13e86b534ab0f5f8 |
|
BLAKE2b-256 | 81764ced5e323532b785a08d09eac74fc84a4c3d8518a15fef73db325b8d2985 |
Hashes for bebleo_smtpd_fixture-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea53f211bc1fad44457903767084d5eac88335f91a5f814caf2a1d8d588e3f05 |
|
MD5 | 1ccf5dc755008c32e15292017961ebb8 |
|
BLAKE2b-256 | bfb6638969eb909e46757af2d21c334f00c76ea0c664c117005de821a26d12cf |