email_notifier
A simple email notifier for general messages or exceptions with easy environment configuration
Description
email_notifier comprises two notifier classes that send emails to a given set of recipients
GeneralNotifier
Sends a general message to a number of recipient emails.
ExceptionNotifier
Sends a nicely formatted exception alert with an appropriate stack trace to a number of recipient emails.
Main Dependencies
Getting Started
-
Install the package
pip install email_notifier
-
Set the environment variables in case you wish wish to have default settings for your email notifier
-
Import the
GeneralNotifierand theExceptionNotifierclasses and use accordinglyfrom email_notifier import GeneralNotifier, ExceptionNotifier # Assuming the environment variables have been set # MAIL_SERVER_HOST=127.0.0.1 # MAIL_SERVER_PORT=10025 # DEFAULT_SENDER_EMAIL_ADDRESS=anne@example.com # DEFAULT_SENDER_EMAIL_PASSWORD=password123123 # DEFAULT_EMAIL_SUBJECT_PREFIX="Test: " # DEFAULT_EMAIL_SIGNATURE="Regards<br/>Sender" # DEFAULT_EMAIL_RECIPIENTS=paul@example.com, albert@example.com general_notifier = GeneralNotifier() general_notifier.send(subject="....", body="....", recipients=["..@...com", "...@...com") # if recipients are not provided, the notifier sends to the default email recipients general_notifier.send(subject="....", body="....") exception_notifier = ExceptionNotifier(is_exception_in_subject=True, subject="...", salutation="...") # The defaults also work in this case # exception_notifier = ExceptionNotifier() def func(): """Just a trial function with exception handling""" try: raise IndexError("Just raising a random exception for exhibition purposes") except IndexError as exp: # an email is sent and the python logger logs the exception exception_notifier.notify(exp) # When the function is called, the notifier will do the needful func()
How to test
-
Clone the repo and enter its root folder
git clone https://github.com/sopherapps/email_notifier.git && cd email_notifier
-
Copy the
.example.envfile to.envand make appropriate edits on itcp .example.env .env
-
Create a virtual environment and activate it
virtualenv -p /usr/bin/python3.6 env && source env/bin/activate
-
Install the dependencies
pip install -r requirements.txt
-
Run the test command
python -m unittest
Environment Configuration
The package leverages environment settings in say a .env file or set directly.
The environment variables include the following.
| Environment Variable | What it is for | Default |
|---|---|---|
| MAIL_SERVER_HOST | The SMTP host | smtp.office365.com |
| MAIL_SERVER_PORT | The SMTP port | 587 |
| DEFAULT_SENDER_EMAIL_ADDRESS | sender email address | "" |
| DEFAULT_SENDER_EMAIL_PASSWORD | sender email password | "" |
| DEFAULT_EMAIL_SUBJECT_PREFIX | subject prefix | "" |
| DEFAULT_EMAIL_SIGNATURE | email signature | "" |
| DEFAULT_EMAIL_RECIPIENTS | comma separated recipient email addresses | "" |
Acknowledgements
This Real Python tutorial on sending emails with python was very helpful. This Real Python tutorial on publishing packages was very helpful
License
Copyright (c) 2020 Martin Ahindura Licensed under the MIT License
Metadata
Release files for email-notifier 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| email_notifier-0.0.1.tar.gz | 5.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| email_notifier-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.6 kB
Release files / email_notifier-0.0.1.tar.gz
| Download URL | email_notifier-0.0.1.tar.gz |
|---|---|
| Size | 5.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2fd2a4af3d9806f673e2065af8e9720f005a7d7a280c1c542ae1bc59a4ac9941
|
|
BLAKE2b-256 checksum How to use checksums |
f92cf8c7922a0f1826747daa5b015cc554ab9affb36378bbb012c25ff984cdf2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.6.9
|
Release files / email_notifier-0.0.1-py3-none-any.whl
| Download URL | email_notifier-0.0.1-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7014a5632feb0ca46dafb383cdf48464e1d88d82b4c45e7f59e1648a2d25e2ac
|
|
BLAKE2b-256 checksum How to use checksums |
ac2e1d75093c01a9019b3a0cc94d4ee1bd41ce6a1a4f8e9529e10f0bed0500e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.6.9
|
Security for email-notifier 0.0.1
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.