Skip to main content

Keg-Mail

nox

Keg-Mail is a basic wrapper around Flask-Mail which adds support for email templates and Mailgun integrations.

Usage

pip install keg-mail

Initialize Keg-Mail in your application:

import flask
from keg import Keg
from keg.signals import app_ready
import keg_mail

bp = flask.Blueprint('main', __name__)
mail = keg_mail.KegMail()


class App(Keg):
    use_blueprints = [bp]


@app_ready.connect
def init_extensions(app):
    """Initialize custom extensions used by this application."""
    mail.init_app(app)

Define email content:

import keg_mail

hello_world_content = keg_mail.EmailContent(
    text='Hello {name}!',
    html='<h1>Hello {name}!</h1>',
)

Validate a recipient before sending:

import keg_mail

address = 'user@example.com'
if keg_mail.Email.address_might_be_invalid(address):
    # The address is invalid or resembles a common typo.
    suggestion = keg_mail.Email.get_invalid_address_suggestions(address)
else:
    # The address has valid syntax and does not resemble a common typo.
    suggestion = None

Send the email:

from app import mail
import app.emails as emails
import keg_mail


@bp.route('/')
def index():
    mail.send_email(
        'you@example.com',
        keg_mail.Email(
            subject='Hello {name}!',
            content=emails.hello_world_content,
        ).format(name='You'),
    )

Test the email:

from app import mail


def test_send_mail():
    with mail.record_messages() as outbox:
        app.test_client.get('/')
        assert len(outbox) == 1
        assert outbox[0].subject == 'Hello You'

Changelog

0.3.1 — 2024-06-21

  • Resolve a missed signal signature change.

0.3.0 — 2024-06-21

  • Automatically pass the reply-to header to Mailgun.
  • Support Flask-Mail 0.10.0 signal changes.

Earlier release notes remain available in changelog.rst.

Development

Copier template

Project structure and tooling mostly derive from Coppy. See its documentation for context and additional instructions. Update this project by following Coppy's template update instructions.

Project setup

  1. Install the host dependencies.
  2. Run uv sync.
  3. Install the hooks with prek install.
  4. Run the checks with nox.

Versions

Use mise run version show to show the current version and mise run version bump to create a version commit and tag.

Metadata

Release files for Keg-Mail 0.20261119.1

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

Source distribution (sdist)

Source distribution for Keg-Mail 0.20261119.1
File Size Uploaded Provenance Actions
keg_mail-0.20261119.1.tar.gz 128.2 kB With provenance Details for keg_mail-0.20261119.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for Keg-Mail 0.20261119.1
File Interpreter ABI Platform Actions
keg_mail-0.20261119.1-py3-none-any.whl Python 3 none any Details for keg_mail-0.20261119.1-py3-none-any.whl

Total release size: 141.2 kB

Release files / keg_mail-0.20261119.1.tar.gz

Download URL keg_mail-0.20261119.1.tar.gz
Size 128.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a9187d5a2439f32fc911c3da320c63f71b6b1dc5e192e4e45bcb986cef7a7c25
BLAKE2b-256 checksum
How to use checksums
eecacfa20781b30852000cf91e493c7dffb49396bdc196986e72aa3f36e44110
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 19, 2026.

Transparency log

Release files / keg_mail-0.20261119.1-py3-none-any.whl

Download URL keg_mail-0.20261119.1-py3-none-any.whl
Size 13.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5fc52c5808019ebbcdaf6a10699e40869b9db06d1e1e3a6070f08cf084ba350c
BLAKE2b-256 checksum
How to use checksums
e597929c7f48f836c40ed050e0ecbcdee72da62aca8cfa529228b5006344899b
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 19, 2026.

Transparency log

Security for Keg-Mail 0.20261119.1

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 keg_mail-0.20261119.1.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 19, 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