diff --git a/webapp/utils.py b/webapp/utils.py index a1ac364..672e5c0 100644 --- a/webapp/utils.py +++ b/webapp/utils.py @@ -18,6 +18,7 @@ from sendgrid.helpers.mail import ( from django.template.loader import render_to_string from django.core.files.base import ContentFile from sikweb.settings import ( + DEPLOY_ENV, FRONTEND_URL, EMAIL_API_KEY, DEFAULT_EMAIL_FROM, @@ -144,14 +145,15 @@ def add_to_mailinglist(email: str): # Already in list, do nothing if err.status_code == 409: pass - # Something went wrong, send notification to maintainer. else: logging.exception("Failed adding user to list") + + # Send email notificcation to maintainer, only in prod + if DEPLOY_ENV == "production": + to = "ilari.ojakorpi@sahkoinsinoorikilta.fi" + subject = "Web error: Failed adding to google groups" + body = "Error code: {}\nError details: {}\nEmail that was not added: {}\n\nAdd user manually to jäsenet groups.".format( + err.status_code, err.error_details, email + ) - to = "ilari.ojakorpi@sahkoinsinoorikilta.fi" - subject = "Web error: Failed adding to google groups" - body = "Error code: {}\nError details: {}\nEmail that was not added: {}\n\nAdd user manually to jäsenet groups.".format( - err.status_code, err.error_details, email - ) - - send_email(to, subject, body) + send_email(to, subject, body)