Skip to main content

CredentiMail Logging System

This project provides a custom logging handler for Python applications that sends log messages via HTTP POST to a remote mail server. It includes structured data models for email and attachment handling using Python dataclasses.

📆 Features

  • Custom logging handler: CredentiMailHandler
  • Data models for email and attachments: MailDetail, Attachment
  • Sends logs to a mail server over HTTP
  • Flask-compatible
  • Includes test command via Flask CLI
  • Installable as a Python package

🚀 Installation

Install the package via pip:

pip install ct-mail-handler

📅 Packaging and Uploading to PyPI

To build and upload the package to PyPI:

1. Install required tools

pip install build twine

2. Build the package

python -m build

This creates dist/ containing .tar.gz and .whl files.

3. Upload to PyPI

python -m twine upload dist/*

You'll be prompted for your PyPI credentials.

For test uploads, use:

python -m twine upload --repository-url https://test.pypi.org/legacy/ dist/*

🚧 Testing Requirements

The dependencies listed in requirements.txt are used only for testing purposes (e.g., Flask CLI and testing libraries). They are not needed when installing this package for runtime use.

Install testing dependencies:

pip install -r requirements.txt

🌐 Usage

1. Add the Logging Handler

from credenti_mail_handler import CredentiMailHandler
import logging

handler = CredentiMailHandler(
    fromaddr="logger@example.com",
    toaddrs=["admin@example.com"],
    subject="Application Error",
    mail_server_url="http://localhost:5000/send-mail"
)

logger = logging.getLogger(__name__)
logger.setLevel(logging.ERROR)
logger.addHandler(handler)

logger.error("This is a test error log.")

2. Email Data Models

MailDetail

  • from_address: str
  • to_address: List[str]
  • subject: str
  • body: str
  • attachments: Optional[List[Attachment]]

Attachment

  • file_content_b64: str
  • file_name: Optional[str>
  • file_type: Optional[str>
  • disposition: Literal['attachment', 'inline']

Add attachments using:

mail_detail.add_attachment(
    file_content_b64="base64content...",
    file_name="report.pdf",
    file_type="application/pdf"
)

🔧 Internal Methods

CredentiMailHandler.emit()

Formats and sends a log record as an email via send_email().

prepare_email()

Returns a MailDetail object from parameters.

send_email()

Uses requests.post() to send the MailDetail as JSON to the mail server.


🔮 Testing

To run tests using Flask CLI:

manage.py

Ensure you have a manage.py file that defines the test command, e.g.:

import click
from flask import Flask

app = Flask(__name__)

@app.cli.command("test")
def test():
    import unittest
    tests = unittest.TestLoader().discover("tests")
    unittest.TextTestRunner().run(tests)

Run tests:

flask --app manage.py test

📅 Folder Structure

.
├── README.md
├── app.py
├── ct_mail_handler/
│   ├── __init__.py
│   ├── credenti_mail_handler.py
│   └── models.py
├── manage.py
├── requirements.txt
├── setup.py
├── tests/
    └── test_handler.py

Metadata

Release files for ct-mail-handler 0.0.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 ct-mail-handler 0.0.2
File Size Uploaded Provenance Actions
ct_mail_handler-0.0.2.tar.gz 4.4 kB Without provenance Details for ct_mail_handler-0.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ct-mail-handler 0.0.2
File Interpreter ABI Platform Actions
ct_mail_handler-0.0.2-py3-none-any.whl Python 3 none any Details for ct_mail_handler-0.0.2-py3-none-any.whl

Total release size: 9.1 kB

Release files / ct_mail_handler-0.0.2.tar.gz

Download URL ct_mail_handler-0.0.2.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
266b5f759d8ffae33cb97f9c5bce1ac63396f995c904a24959b1b88b75204558
BLAKE2b-256 checksum
How to use checksums
08cbdcde47756d54c2151893dd1bd7fb82005ca579fbbb2f62a4ffb357e64d9a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.15

Release files / ct_mail_handler-0.0.2-py3-none-any.whl

Download URL ct_mail_handler-0.0.2-py3-none-any.whl
Size 4.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c653c9b24f54100cff8bb0a4e5366ffc59a3cbdc0c1f2a4631746dba468f4028
BLAKE2b-256 checksum
How to use checksums
af1424967729332fea329067bc01e8361e7e59fb8d38601d43a7fc09404d44a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.15

Security for ct-mail-handler 0.0.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files No provenance

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