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 details)

Uploaded Source

Built Distribution

smtp_test_server-0.1.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file smtp_test_server-0.1.0.tar.gz.

File metadata

  • Download URL: smtp_test_server-0.1.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.4 Darwin/23.1.0

File hashes

Hashes for smtp_test_server-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b64ee81af6cb2a44031ce2b9f885faeeb76f088d9c7bcfcee4d11751ea5d9aa6
MD5 b2cceaae69aa094e1bca03e27b48ba3f
BLAKE2b-256 af80230bfaf67256ca5a9189e070d80a6547dbadbeb1fa0cdf8d60e616679297

See more details on using hashes here.

File details

Details for the file smtp_test_server-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for smtp_test_server-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d19387bf1e7f53b0c1ceedb9e8dd6147d0189bae93ccd90145c278c6a97919c6
MD5 e9d272a9c68fb5e6e0d920d9c3829dbd
BLAKE2b-256 6fb8a1487ec4a2287308ca8e445fc9f416885beca11cab3879401cc15623ab92

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