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.0.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.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: failmail-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 d14a898a89490a1f9b2ae04a4a9318d1c53816cbd595f9bb2f67d99177891dda
MD5 b2a642739e6823fcdeecd7a65e6f7368
BLAKE2b-256 9f4e2bb414d268d333ad0a4c45e8670223effbdda7cbf11c3791b6af88c4ccd3

See more details on using hashes here.

Provenance

The following attestation bundles were made for failmail-0.1.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: failmail-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 62e1370450fefd9161eb047c38b04d07d5f0aac5e7e778846dccf705187ea702
MD5 7c3972c63b457f3e22a61bc6044d6212
BLAKE2b-256 b21c54916bb77368e1d72c42df8658559341b1e332081f6828bf24ce51860e05

See more details on using hashes here.

Provenance

The following attestation bundles were made for failmail-0.1.0-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