Skip to content

Commit

Permalink
task/TUP-528: send an email when users submit a form (#392)
Browse files Browse the repository at this point in the history
* send an email when users submit a form

* move email settings to non-local conf.

---------

Co-authored-by: Jake Rosenberg <[email protected]>
Co-authored-by: Wesley B <[email protected]>
  • Loading branch information
3 people authored Dec 12, 2023
1 parent 7e9f1a8 commit 7e02a25
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
22 changes: 22 additions & 0 deletions apps/tup-cms/src/apps/portal/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.dispatch import receiver
from djangocms_forms.signals import form_submission
from django.conf import settings
from django.core.mail import send_mail


logger = logging.getLogger(f"portal.{__name__}")
Expand Down Expand Up @@ -42,10 +43,31 @@ def submit_ticket(form_data):
requests.post(f"{service_url}/tickets/noauth", data=ticket_data, files=[])


def send_confirmation_email(form_name, form_data):
email_body = """
<p>Hello,</p>
<p>
Thank you for submitting a form on the TACC website.
</p>
<p>
We will act on your request according to the information provided on the form webpage.
</p>
- TACC
"""
send_mail(
f"TACC Form Submission Received: {form_name}",
email_body,
"[email protected]",
[form_data["email"]],
html_message=email_body)


def callback(form, cleaned_data, **kwargs):
logger.debug(f"received submission from {form.name}")
if form.name == 'rt-ticket-form':
submit_ticket(cleaned_data)
else:
send_confirmation_email(form.name, cleaned_data)


class PortalConfig(AppConfig):
Expand Down
3 changes: 3 additions & 0 deletions apps/tup-cms/src/taccsite_cms/secrets.sample.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
TUP_SERVICES_ADMIN_JWT = "CHANGEME"

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = ""

0 comments on commit 7e02a25

Please sign in to comment.