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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d14a898a89490a1f9b2ae04a4a9318d1c53816cbd595f9bb2f67d99177891dda
|
|
| MD5 |
b2a642739e6823fcdeecd7a65e6f7368
|
|
| BLAKE2b-256 |
9f4e2bb414d268d333ad0a4c45e8670223effbdda7cbf11c3791b6af88c4ccd3
|
Provenance
The following attestation bundles were made for failmail-0.1.0.tar.gz:
Publisher:
python-publish.yml on spyel/failmail
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
failmail-0.1.0.tar.gz -
Subject digest:
d14a898a89490a1f9b2ae04a4a9318d1c53816cbd595f9bb2f67d99177891dda - Sigstore transparency entry: 166209537
- Sigstore integration time:
-
Permalink:
spyel/failmail@2dcf77ae1befeab394fbb52cd7144c60dd2bf937 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/spyel
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@2dcf77ae1befeab394fbb52cd7144c60dd2bf937 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
62e1370450fefd9161eb047c38b04d07d5f0aac5e7e778846dccf705187ea702
|
|
| MD5 |
7c3972c63b457f3e22a61bc6044d6212
|
|
| BLAKE2b-256 |
b21c54916bb77368e1d72c42df8658559341b1e332081f6828bf24ce51860e05
|
Provenance
The following attestation bundles were made for failmail-0.1.0-py3-none-any.whl:
Publisher:
python-publish.yml on spyel/failmail
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
failmail-0.1.0-py3-none-any.whl -
Subject digest:
62e1370450fefd9161eb047c38b04d07d5f0aac5e7e778846dccf705187ea702 - Sigstore transparency entry: 166209538
- Sigstore integration time:
-
Permalink:
spyel/failmail@2dcf77ae1befeab394fbb52cd7144c60dd2bf937 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/spyel
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@2dcf77ae1befeab394fbb52cd7144c60dd2bf937 -
Trigger Event:
release
-
Statement type: