Template email subject lines

This commit is contained in:
Neil Martinsen-Burrell 2023-03-28 13:53:32 -05:00
parent 4b6771565b
commit 2693641f2b
No known key found for this signature in database
GPG key ID: 6A3C818CC10D0184
5 changed files with 18 additions and 5 deletions

View file

@ -476,6 +476,7 @@ class DomainApplication(TimeStampedModel):
try: try:
send_templated_email( send_templated_email(
"emails/submission_confirmation.txt", "emails/submission_confirmation.txt",
"emails/submission_confirmation.subject.txt",
self.submitter.email, self.submitter.email,
context={"id": self.id, "domain_name": self.requested_domain.name}, context={"id": self.id, "domain_name": self.requested_domain.name},
) )

View file

@ -0,0 +1 @@
You are invited to manage {{ domain.name }} on get.gov

View file

@ -0,0 +1 @@
Thank you for applying for a .gov domain

View file

@ -13,16 +13,22 @@ class EmailSendingError(RuntimeError):
pass pass
def send_templated_email(template_name: str, to_address: str, context={}): def send_templated_email(
template_name: str, subject_template_name: str, to_address: str, context={}
):
"""Send an email built from a template to one email address. """Send an email built from a template to one email address.
template_name is relative to the same template context as Django's HTML template_name and subject_template_name are relative to the same template
templates. context gives additional information that the template may use. context as Django's HTML templates. context gives additional information
that the template may use.
""" """
template = get_template(template_name) template = get_template(template_name)
email_body = template.render(context=context) email_body = template.render(context=context)
subject_template = get_template(subject_template_name)
subject = subject_template.render(context=context)
try: try:
ses_client = boto3.client( ses_client = boto3.client(
"sesv2", "sesv2",
@ -40,7 +46,7 @@ def send_templated_email(template_name: str, to_address: str, context={}):
Destination={"ToAddresses": [to_address]}, Destination={"ToAddresses": [to_address]},
Content={ Content={
"Simple": { "Simple": {
"Subject": {"Data": "Thank you for applying for a .gov domain"}, "Subject": {"Data": subject},
"Body": {"Text": {"Data": email_body}}, "Body": {"Text": {"Data": email_body}},
}, },
}, },

View file

@ -79,8 +79,12 @@ class DomainAddUserView(DomainPermission, FormMixin, DetailView):
try: try:
send_templated_email( send_templated_email(
"emails/domain_invitation.txt", "emails/domain_invitation.txt",
"emails/domain_invitation.subject.txt",
to_address=email_address, to_address=email_address,
context={"domain_url": self._domain_abs_url()}, context={
"domain_url": self._domain_abs_url(),
"domain": self.object,
},
) )
except EmailSendingError: except EmailSendingError:
messages.warning(self.request, "Could not send email invitation.") messages.warning(self.request, "Could not send email invitation.")