-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CMD-72: All CMS Forms Should Send Confirmation E-Mail (#817)
* add email confirmation capability * remove unnecessary files, add to settings.py. * make comment adjustments * fix: typo in email messages * fix: typo in email messages * Update apps/email_management/apps.py Co-authored-by: Wesley B <62723358+wesleyboar@users.noreply.github.com> * unindent paragraphs * update indentation --------- Co-authored-by: Wesley B <62723358+wesleyboar@users.noreply.github.com>
- Loading branch information
1 parent
cea6b4e
commit 0a193ef
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from django.apps import AppConfig | ||
import logging | ||
from djangocms_forms.signals import form_submission | ||
from django.core.mail import send_mail | ||
|
||
logger = logging.getLogger(f"portal.{__name__}") | ||
|
||
def send_confirmation_email(form_name, form_data): | ||
|
||
from django.contrib.sites.models import Site | ||
|
||
# Get the current site | ||
current_site = Site.objects.get_current() | ||
|
||
# Get the site name | ||
site_name = current_site.name | ||
|
||
text_body = f""" | ||
Greetings, | ||
You have successfully submitted a form on the {site_name} website. Thank you for your submission. | ||
Sincerely, | ||
{site_name} Communications | ||
""" | ||
email_body = f""" | ||
<p>Greetings,</p> | ||
<p> | ||
You have successfully submitted a form on the {site_name} website. Thank you for your submission. | ||
</p> | ||
<p> | ||
Sincerely,<br> | ||
{site_name} Communications | ||
</p> | ||
""" | ||
send_mail( | ||
f"TACC Form Submission Received: {form_name}", | ||
text_body, | ||
"no-reply@tacc.utexas.edu", | ||
[form_data['email']], | ||
html_message=email_body) | ||
|
||
|
||
def callback(form, cleaned_data, **kwargs): | ||
logger.debug(f"received submission from {form.name}") | ||
logger.debug(type(cleaned_data)) | ||
if ('email' in cleaned_data): | ||
send_confirmation_email(form.name, cleaned_data) | ||
|
||
class EmailManagementConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'apps.email_management' | ||
|
||
def ready(self): | ||
form_submission.connect(callback) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters