From 3bbd1eb19975c3d15176c24e5d5d73c9cd9cae39 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Tue, 10 Feb 2026 01:14:41 +0000
Subject: [PATCH] Fix email template formatting - convert newlines to br tags
and increase header padding
Co-authored-by: cadtoolbox <12723486+cadtoolbox@users.noreply.github.com>
---
backend/app/services/email_service.py | 44 ++---
.../tests/unit/services/test_email_service.py | 162 ++++++++++++++++++
2 files changed, 184 insertions(+), 22 deletions(-)
create mode 100644 backend/tests/unit/services/test_email_service.py
diff --git a/backend/app/services/email_service.py b/backend/app/services/email_service.py
index 937adfdd6..c308c4e39 100644
--- a/backend/app/services/email_service.py
+++ b/backend/app/services/email_service.py
@@ -67,9 +67,7 @@ async def get_notification_template(db: AsyncSession, event_type: str) -> Notifi
Returns:
NotificationTemplate object or None if not found
"""
- result = await db.execute(
- select(NotificationTemplate).where(NotificationTemplate.event_type == event_type)
- )
+ result = await db.execute(select(NotificationTemplate).where(NotificationTemplate.event_type == event_type))
return result.scalar_one_or_none()
@@ -103,17 +101,19 @@ async def get_smtp_settings(db: AsyncSession) -> SMTPSettings | None:
# Fetch all SMTP-related settings
result = await db.execute(
select(Settings).where(
- Settings.key.in_([
- "smtp_host",
- "smtp_port",
- "smtp_username",
- "smtp_password",
- "smtp_use_tls",
- "smtp_security",
- "smtp_auth_enabled",
- "smtp_from_email",
- "smtp_from_name",
- ])
+ Settings.key.in_(
+ [
+ "smtp_host",
+ "smtp_port",
+ "smtp_username",
+ "smtp_password",
+ "smtp_use_tls",
+ "smtp_security",
+ "smtp_auth_enabled",
+ "smtp_from_email",
+ "smtp_from_name",
+ ]
+ )
)
)
settings_dict = {s.key: s.value for s in result.scalars().all()}
@@ -417,8 +417,8 @@ async def create_welcome_email_from_template(
text_body = render_template(template.body_template, variables)
# Create HTML version with embedded login button
- # Escape text_body to prevent XSS vulnerabilities
- escaped_text_body = html.escape(text_body)
+ # Escape text_body to prevent XSS vulnerabilities and convert newlines to
tags
+ escaped_text_body = html.escape(text_body).replace("\n", "
\n")
html_body = f"""