Skip to main content

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

build

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


Download files

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

Source Distribution

bebleo-smtpd-fixture-0.2.1.tar.gz (9.7 kB view hashes)

Uploaded Source

Built Distribution

bebleo_smtpd_fixture-0.2.1-py3-none-any.whl (10.4 kB view hashes)

Uploaded Python 3

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