Skip to main content

ingot-mail

ci License

The mail of Ingots applications. An addon of Ingots.

Status: pre-alpha: the mail and its mailer, the interface of a backend with its contract, the mailer in memory and the mailer of SMTP on aiosmtplib.

For Consumers

Install

uv add ingot-mail               # the core and the mailer in memory
uv add "ingot-mail[aiosmtplib]"  # the mailer of SMTP

Integrate

An application of Ingots has its own configs, settings, logging and project; each takes the class of the addon among its bases:

# app/project.py
import typing as t

from ingot_mail import MailProject
from ingot_mail.contrib.memory import MemoryMailer
from ingot_mail.logging import MailLoggingUnit
from ingot_mail.mail import MailUnit
from ingot_mail.settings import MailSettingsUnit
from ingot_mail.settings.configs import MailConfigs
from ingots.puer import Slot


class AppConfigs(MailConfigs):
    pass


class AppSettingsUnit(MailSettingsUnit):
    configs = Slot(AppConfigs)


class AppLoggingUnit(MailLoggingUnit):
    project: "AppProject"


class AppMailUnit(MailUnit):
    mailer = Slot(MemoryMailer)


class AppProject(MailProject):
    env_configs_prefix = "APP"
    settings = Slot(AppSettingsUnit)
    logging = Slot(AppLoggingUnit)
    mail = Slot(AppMailUnit)

The slot mailer of MailUnit is abstract: the application declares a backend. MemoryMailer delivers nothing and keeps the mail for the tests, get_sent().

With other addons, their classes join the same bases: class AppConfigs(MailConfigs, MongoDbConfigs), and so on, as the addon guide of Ingots shows. An application with this addon alone may inherit MailProject and nothing more.

The application runs through its own __main__.py:

# app/__main__.py
import sys

from ingots.defaults.logging import configure_startup_logging
from ingots.puer.cli import CommandRunner

from .project import AppProject

configure_startup_logging()
sys.exit(CommandRunner(AppProject).run())
uv run python -m app settings list    # the configs, MAIL_* among them
uv run python -m app logging info     # the loggers, ingot_mail among them

Send by SMTP

AiosmtplibMailer of ingot_mail.contrib.aiosmtplib, with the extra aiosmtplib, sends a mail by the server of MAIL_SMTP_*, a connection a mail:

from ingot_mail.contrib.aiosmtplib import AiosmtplibMailer


class AppMailUnit(MailUnit):
    mailer = Slot(AiosmtplibMailer)

It secures the connection by STARTTLS by default, verifying the certificate of the server by the roots of the system; MAIL_SMTP_TLS=TLS for the port 465, NONE for a server of the tests alone, such as Mailpit. A subclass reads other configs by its hooks, _get_host() and the rest, and verifies by other roots by _get_tls_context(). The logger ingot_mail tells each mail sent by its message id, never its addresses nor its text.

Send

from ingot_mail.mail import Mail

mail = Mail(to=("al@b.c",), subject="Welcome", text="Hello, Al!\n")
await self.project.mail.mailer.send(mail)

A mail is from its sender, or from MAIL_FROM when it tells none. Its headers are the application's own, {"X-Request-ID": request_id} for one; those the mailer sets, From, To, Subject, Date, Message-ID, the copies and the content, it may not. A header unfit to send, an empty one, or one with a line break, which would inject another header, is refused before the backend by MailHeaderError; a mail the server did not take is MailDeliveryError, is_transient when sending it again later may succeed. The retry is the caller's.

Test a backend

A backend runs the contract of the mailer, MailerContract of ingot_mail.testing.contracts, telling the project and where its mail is read back:

class AppMailerTestCase(MailerContract, unittest.IsolatedAsyncioTestCase):
    async def create_project(self) -> MailProject:
        return AppProject()

    async def get_delivered(self) -> tuple[Mail, ...]:
        ...

Configs

Set as environment variables with the prefix of the project (APP_MAIL_LOGGING_LEVEL), in a --configs-file or with --config.

Name Default Meaning
MAIL_LOGGING_LEVEL INFO the level of the logger of the addon, ingot_mail
MAIL_FROM noreply@localhost the sender of a mail telling none
MAIL_SMTP_HOST localhost the server of SMTP
MAIL_SMTP_PORT 587 its port
MAIL_SMTP_USER the user to log in as; empty, no login
MAIL_SMTP_PASSWORD its password, hidden in the listings
MAIL_SMTP_TLS MailSmtpTls.STARTTLS how the connection is secured: STARTTLS, TLS or NONE
MAIL_SMTP_TIMEOUT 30.0 the seconds to wait for the server at each step

Development

Requires uv and make; uv fetches the interpreters it needs.

make                 # the target list
make check           # everything CI runs: lint, test, coverage, wheel-test, integration, cl-check
make integration     # the mailer of SMTP against the Mailpits of docker-compose.yml
make format          # black
make all             # build the sdist and the wheel into dist/
  • Every change users should know about adds a news fragment to changelog.d/ (see its README).
  • A release is a pull request setting the version (uv version X.Y.Z) and collating the changelog (make cl-build VERSION=X.Y.Z), then the tag vX.Y.Z on main: the release workflow publishes the tested build to TestPyPI, tests it as installed from there, then publishes it to PyPI. Run by hand, it rehearses on TestPyPI only.

Metadata

Release files for ingot-mail 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ingot-mail 0.2.0
File Size Uploaded Provenance Actions
ingot_mail-0.2.0.tar.gz 18.8 kB With provenance Details for ingot_mail-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ingot-mail 0.2.0
File Interpreter ABI Platform Actions
ingot_mail-0.2.0-py3-none-any.whl Python 3 none any Details for ingot_mail-0.2.0-py3-none-any.whl

Total release size: 40.2 kB

Release files / ingot_mail-0.2.0.tar.gz

Download URL ingot_mail-0.2.0.tar.gz
Size 18.8 kB
Tags Source
SHA-256 checksum
How to use checksums
bde0057fb1a19bedef8b63e7c752f686218e14f85dd39919c13ede639bb91b91
BLAKE2b-256 checksum
How to use checksums
57b7754db36662e8ac3ac465fa51c7db8ef129b87d7a2de0f493719cf134c5a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

Release files / ingot_mail-0.2.0-py3-none-any.whl

Download URL ingot_mail-0.2.0-py3-none-any.whl
Size 21.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
16ac0d699465543382f6b5e164e030cbd54d3c473736a83386f44c3ddf2ec43e
BLAKE2b-256 checksum
How to use checksums
d58645b26cec6db347dac54f9091515912a6a0a8f6f15e7a5d6bc29e5312afba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

Security for ingot-mail 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for ingot_mail-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page