Skip to content

Commit

Permalink
🧑‍💻 [#4895] Add custom headers to confirmation emails
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorvanwijk committed Dec 11, 2024
1 parent 230d7b2 commit 76c2865
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/openforms/appointments/tests/test_confirmation_emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from django.utils.translation import gettext as _

from openforms.config.models import GlobalConfiguration
from openforms.emails.constants import EmailContentTypeChoices, EmailEventChoices
from openforms.formio.typing import Component
from openforms.submissions.tasks import schedule_emails
from openforms.submissions.tests.factories import SubmissionFactory
Expand Down Expand Up @@ -302,3 +303,33 @@ def test_cancel_and_change_instructions(self):
with self.subTest(type="plain text"):
self.assertIn(cancel_link, message_text)
self.assertNotIn(change_link, message_text)

def test_headers_present_in_confirmation_email(self):
appointment = AppointmentFactory.create(
plugin="with-email",
submission__language_code="nl",
submission__form__is_appointment_form=True,
submission__form__send_confirmation_email=True,
products=[Product(identifier="dummy", name="")],
appointment_info__registration_ok=True,
contact_details_meta=[LAST_NAME, EMAIL],
contact_details={"lastName": "Powers", "email": "[email protected]"},
)
send_confirmation_email(appointment.submission)

self.assertEqual(len(mail.outbox), 1)
message = mail.outbox[0]

# UUID is not a constant, so just test if it exists
submission_uuid = message.extra_headers.pop("X-OF-Content-UUID", None)
self.assertIsNotNone(submission_uuid)

# Test remaining headers
self.assertEqual(
message.extra_headers,
{
"Content-Language": "nl",
"X-OF-Content-Type": EmailContentTypeChoices.submission,
"X-OF-Event": EmailEventChoices.confirmation,
},
)
13 changes: 13 additions & 0 deletions src/openforms/submissions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
get_confirmation_email_context_data,
get_confirmation_email_templates,
)
from openforms.emails.constants import (
X_OF_CONTENT_TYPE_HEADER,
X_OF_CONTENT_UUID_HEADER,
X_OF_EVENT_HEADER,
EmailContentTypeChoices,
EmailEventChoices,
)
from openforms.emails.utils import (
render_email_template,
send_mail_html,
Expand Down Expand Up @@ -208,6 +215,12 @@ def send_confirmation_email(submission: Submission) -> None:
cc=cc_emails,
text_message=text_content,
theme=submission.form.theme,
extra_headers={
"Content-Language": submission.language_code,
X_OF_CONTENT_TYPE_HEADER: EmailContentTypeChoices.submission,
X_OF_CONTENT_UUID_HEADER: str(submission.uuid),
X_OF_EVENT_HEADER: EmailEventChoices.confirmation,
},
)
except Exception as e:
logevent.confirmation_email_failure(submission, e)
Expand Down

0 comments on commit 76c2865

Please sign in to comment.