Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EmailNotifications: provide example #428

Merged
merged 1 commit into from
Sep 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions apstools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,32 @@ class EmailNotifications(object):
send email notifications when requested

use default OS mail utility (so no credentials needed)

EXAMPLE

Send email(s) when `feedback_limits_approached`
(a hypothetical boolean) is `True`::

# setup
from apstools.utils import EmailNotifications

SENDER_EMAIL = "instrument_user@email.host.tld"

email_notices = EmailNotifications(SENDER_EMAIL)
email_notices.add_addresses(
# This list receives email when send() is called.
"joe.user@goodmail.com",
"instrument_team@email.host.tld",
# others?
)

# ... later

if feedback_limits_approached:
# send emails to list
subject = "Feedback problem"
message = "Feedback is very close to its limits."
email_notices.send(subject, message)
"""

def __init__(self, sender=None):
Expand Down