-
-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Chirag Jain edited this page Sep 5, 2021
·
6 revisions
Send async email and slack notifications via Python. Get updates/crashlogs from your scripts with ease.
python -m venv env
source env/bin/activate
pip install notipyer
Notipyer currently supports Gmail accounts as senders. To allow the library to use your Gmail account, make the following changes:
- Turn on 2-Step authentication. Ref
- Create an app password. Ref
- While creating an app password, select app as "Other (Custom name)" and enter a name of your choice.
- Use the password obtained from app password for the configuration step below.
- More information can be obtained on the wiki page here
from notipyer.email_notify import set_email_config
SENDER_EMAIL = 'myemail@gmail.com'
SENDER_PASS = 'my_app_password'
SENDER_NAME = 'my name'
set_email_config(SENDER_EMAIL, SENDER_PASS, SENDER_NAME)
from notipyer.email_notify import send_email
subject = 'My Email Subject'
body = 'My Email Body'
to_recipients = ['to-email-1@domain.com', 'toemail2@domain.com'] # Can be None
cc_recipients = ['cc-email-1@domain.com', 'cc-email-2@domain.com'] # Can be None
bcc_recipients = ['bcc-email-1@domain.com', 'bcc-email-2@domain.com'] # Can be None
send_email(subject, body, to_recipients, cc_recipients, bcc_recipients)
Notipyer currently supports running a single workplace install only.
For setting up token keys for using slack notifications, follow the wiki page here
from notipyer.slack_notify import set_slack_token_config
# Follow the wiki for getting the bot token
BOT_TOKEN = 'xoxb-12345678990123-1234567890123-abcdefghijklmnopqrstuvwx'
set_slack_token_config(BOT_TOKEN)
from notipyer.slack_notify import send_message
# the bot should be added to the channel
channel = 'my-channel-name'
message = 'my-message'
set_slack_token_config(SLACK_TOKEN)
send_message(channel, message)