Send confirmation emails on application submission

This commit is contained in:
Neil Martinsen-Burrell 2023-02-13 14:19:50 -06:00
parent 3e46683d62
commit 884a58cf10
No known key found for this signature in database
GPG key ID: 6A3C818CC10D0184
9 changed files with 594 additions and 216 deletions

View file

@ -0,0 +1,31 @@
"""Utilities for sending emails."""
import boto3
from django.conf import settings
from django.template.loader import get_template
def send_templated_email(template_name: str, to_address: str, context={}):
"""Send an email built from a template to one email address.
template_name is relative to the same template context as Django's HTML
templates. context gives additional information that the template may use.
"""
template = get_template(template_name)
email_body = template.render(context=context)
ses_client = boto3.client(
"sesv2",
aws_access_key_id=settings.AWS_ACCESS_KEY_ID,
aws_secret_access_key=settings.AWS_SECRET_ACCESS_KEY,
)
ses_client.send_email(
FromEmailAddress=settings.DEFAULT_FROM_EMAIL,
Destination={"ToAddresses": [to_address]},
Content={
"Subject": {"Data": "Thank you for applying for a .gov domain"},
"Body": {"Text": {"Data": email_body}},
},
)