Skip to main content

Keg-Mail

nox codecov

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.2

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.2
File Size Uploaded Provenance Actions
keg_mail-0.20261119.2.tar.gz 129.7 kB With provenance Details for keg_mail-0.20261119.2.tar.gz

Built distribution (wheel)

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

Total release size: 143.2 kB

Release files / keg_mail-0.20261119.2.tar.gz

Download URL keg_mail-0.20261119.2.tar.gz
Size 129.7 kB
Tags Source
SHA-256 checksum
How to use checksums
b4193d189abd2c3764f036d3d8635d3241c982959ae97a126a3e12da3d9aece7
BLAKE2b-256 checksum
How to use checksums
c78c3e7ddcc73443c58974b911d8b1946f8dde581d0c499047ab1b0e799bd5b1
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.2-py3-none-any.whl

Download URL keg_mail-0.20261119.2-py3-none-any.whl
Size 13.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e94562466a55411d416243cd882fcab136f4626dacb2f890546284c04b3f1cdd
BLAKE2b-256 checksum
How to use checksums
3a7ec758d70dccf2cda6f7c4758ef12bfd889401974aa2a2362538f68c761d39
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.2

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.2.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