Lightweight, reusable email class in Python; ideal for triggering alerts with 3rd party SMTP.
angela 2862e22ba2 github handle update | 6 years ago | |
---|---|---|
classes | 6 years ago | |
.htaccess | 6 years ago | |
LICENSE | 6 years ago | |
README.md | 6 years ago | |
config.json | 6 years ago | |
versionCheck.py | 6 years ago |
Reusable class for Python with JSON config; ideal for plaintext alerts. Tested on Debian 9 Stretch
Dependences
Install
Via terminal, run:
git clone https://github.com/angela-d/simple-python-email-class.git && cd simple-python-email-class
chmod u+x versionCheck.py && cd ..
Rename the directory to suit your project:
mv simple-python-email-class newdirname
bash
if not sys.version_info[:3] >= (3, 5):
To:
bash
if not sys.version_info[:4] >= (4, 5):
Execute the script in cli:
bash
python3 versionCheck.py
Note: versionCheck.py is an optional component and not required for the emailer to run.
Anywhere you'd like to trigger an email during an exception, simply call:
# import the required modules & emailer class
import json
from classes.emailer import Emailer
# open & read config.json
# variable names can be changed to suit your application
with open('config.json') as developerAlerts:
devs = json.load(developerAlerts)
#ensure you modify the trigger variables below to sync with your json extraction
sendAnEmail = Emailer(
devs['dev_alerts']['from'],
devs['dev_alerts']['to'],
devs['dev_alerts']['subject'],
devs['dev_alerts']['message'],
devs['dev_alerts']['server'],
devs['dev_alerts']['outgoing_port'],
devs['dev_alerts']['pw']
)