Skip to main content

Simple SMTP test server for running unit and integration tests.

Project description

smtp-test-server

Based on the aiosmtpd, this packages offers you a simple way to integrate a SMTP server into your test code.

Currently, the server does not support authentication, TLS or anything special instead of sending mails.

All mails are collected in the messages property of the mock and can be evaluated there.

Looking for a pytest SMTP mock fixture? Take a look at this project: git.codebau.dev/pytest-plugins/pytest-smtp-test-server.

Installation

Installation with "pip"

pip install smtp-test-server

Installation with "poetry"

poetry add --group dev smtp-test-server

Usage

Simple usage, with auto assigning a free port number on 127.0.0.1:

from smtp_test_server.context import SmtpMockServer

def test_send_mail():
    with SmtpMockServer() as smtp_mock:
        my_mail_method(smtp_host=smtp_mock.host, smtp_port=smtp_mock.port)
    assert len(smtp_mock.messages) == 1
    assert smtp_mock.messages[0]["from"] == "my-test@sender.org"

Want to have more control over host and port? Use it like this:

with SmtpMockServer(bind_host="223.12.9.177", bind_port=2525):
    ...

Ports are automatically closed when leaving the context.

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

smtp_test_server-0.1.0.tar.gz (5.1 kB view hashes)

Uploaded Source

Built Distribution

smtp_test_server-0.1.0-py3-none-any.whl (5.8 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