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

email: don't send emails when notifications are disabled #407

Merged
Show file tree
Hide file tree
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
21 changes: 20 additions & 1 deletion reana_commons/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@
from reana_commons.errors import REANAEmailNotificationError

# Email configuration
REANA_NOTIFICATIONS_ENABLED = bool(
strtobool(os.getenv("REANA_NOTIFICATIONS_ENABLED", "True"))
)
REANA_EMAIL_SMTP_SERVER = os.getenv("REANA_EMAIL_SMTP_SERVER")
REANA_EMAIL_SMTP_PORT = os.getenv("REANA_EMAIL_SMTP_PORT")
REANA_EMAIL_LOGIN = os.getenv("REANA_EMAIL_LOGIN")
REANA_EMAIL_SENDER = os.getenv("REANA_EMAIL_SENDER")
REANA_EMAIL_RECEIVER = os.getenv("REANA_EMAIL_RECEIVER")
REANA_EMAIL_PASSWORD = os.getenv("REANA_EMAIL_PASSWORD")
REANA_EMAIL_SMTP_SSL = bool(strtobool(os.getenv("REANA_EMAIL_SMTP_SSL", "False")))
REANA_EMAIL_SMTP_STARTTLS = bool(
Expand All @@ -35,13 +39,28 @@
login_email=REANA_EMAIL_LOGIN,
sender_email=REANA_EMAIL_SENDER,
):
"""Send emails from REANA platform."""
"""Send emails from REANA platform.

:param receiver_email: Email address of the receiver.
:param subject: Subject of the email.
:param body: Body of the email.
:param login_email: Email address of the logged user.
:param sender_email: Email address of the sender.
:raises REANAEmailNotificationError: If email cannot be sent, e.g. due to
missing configuration.
"""
message = EmailMessage()
message["From"] = f"REANA platform <{sender_email}>"
message["To"] = receiver_email
message["Subject"] = subject
message.set_content(body)

if not REANA_NOTIFICATIONS_ENABLED:
raise REANAEmailNotificationError(

Check warning on line 59 in reana_commons/email.py

View check run for this annotation

Codecov / codecov/patch

reana_commons/email.py#L59

Added line #L59 was not covered by tests
"An email was about to be sent, but REANA notifications are disabled, "
"therefore it won't be dispatched."
)

if not (REANA_EMAIL_SMTP_SERVER and REANA_EMAIL_SMTP_PORT):
raise REANAEmailNotificationError(
"Cannot send email, missing server and port configuration. "
Expand Down
2 changes: 1 addition & 1 deletion reana_commons/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@

from __future__ import absolute_import, print_function

__version__ = "0.9.3a5"
__version__ = "0.9.3a6"

Check warning on line 17 in reana_commons/version.py

View check run for this annotation

Codecov / codecov/patch

reana_commons/version.py#L17

Added line #L17 was not covered by tests