Skip to main content

A Python package to notify users via email when exceptions occur.

Project description

✉️ Failmail

Failmail is a Python package designed to send email notifications when exceptions are raised in your application. It offers an easy-to-use registry system to associate specific exceptions with customizable email alerts. You can specify the recipients, subject, body, and format (plain-text or HTML) for the notifications.

Note: Failmail is in early development. The API may change as new features are added and refined.

🌱 Getting Started

🔧 Installation

To install the package, run:

pip install failmail

For the latest development version directly from the repository, use:

pip install git+https://github.com/spyel/failmail.git

🖥️ Usage

First, create an instance of ExceptionNotifier and configure it with your SMTP server details:

from failmail import ExceptionNotifier

# Set up the notifier with your SMTP server details
notifier = ExceptionNotifier(
    host=('smtp.example.com', 587),       # SMTP server address and port
    sender_email='sender@example.com',    # Sender's email address
    credentials=('username', 'password'), # SMTP login credentials (optional)
    encryption='tls'                      # Encryption type: 'tls' or 'ssl' or 'none'
)

Next, register specific exceptions along with their corresponding email notifications. You can define the recipients, subject, body, and the format of the email (either plain or html):

notifier.register_exception(
    exception_type=ValueError,  # The exception to register
    recipients=['admin@example.com'],
    subject='Error: ${error_type} occurred',
    body='An error of type ${error_type} occurred at ${timestamp}.\n\nMessage: ${error_message}\n\nTraceback:\n${error_traceback}',
    body_type='plain'  # Use 'html' for HTML format
)

When an exception occurs, use the notify() method to send the email notification:

try:
    # Some code that may raise an exception
    raise ValueError("Something went wrong!")
except Exception as e:
    # Notify recipients when an exception is raised
    notifier.notify(e)

You can also include additional context to customize the email notification. This context will be used to format the subject and body of the email:

additional_context = {
    'custom_info': 'Additional data for the notification'
}
notifier.notify(e, additional_context=additional_context)

📄 License

This project is licensed under the MIT License. See the LICENSE file for details.

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

failmail-0.1.1.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

failmail-0.1.1-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file failmail-0.1.1.tar.gz.

File metadata

  • Download URL: failmail-0.1.1.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for failmail-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8adf73818b6e40eaeb00af4888c8fb033d872a9529fea41f6c0d3a9fab4ef230
MD5 cbcc77fe3ab492dfc45727aa43cf1382
BLAKE2b-256 cc31e6f7489c135206be13fbac62c345fb1510c45701ed494e3b44c64bf402cc

See more details on using hashes here.

Provenance

The following attestation bundles were made for failmail-0.1.1.tar.gz:

Publisher: python-publish.yml on spyel/failmail

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file failmail-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: failmail-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for failmail-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3c278b31a5fb063842ce59f2c99ce5c27d281c6ac9d6a935bda64ebc0fc3e755
MD5 51c2ec4b91164a161c63f2ff82848142
BLAKE2b-256 bc2b2971331f489f4f97cc52fe9e367d22ffdfb292ef4b4a7fa72f81e138aa76

See more details on using hashes here.

Provenance

The following attestation bundles were made for failmail-0.1.1-py3-none-any.whl:

Publisher: python-publish.yml on spyel/failmail

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page