From 3d0f5e4f04020ee564314080848b5ab9c82fc942 Mon Sep 17 00:00:00 2001
From: smueller
Date: Tue, 7 Jul 2026 15:42:12 +0200
Subject: [PATCH 1/2] Enhance newsletter functionality with contact email
support
- Added support for a contact email in newsletter generation, allowing users to specify a reply-to address.
- Updated the SMTP settings to include a reply-to field in the configuration.
- Modified the newsletter templates to display the contact email in plain text and HTML formats.
- Improved the dashboard UI to allow users to set the reply-to address when configuring SMTP settings.
---
app/main.py | 16 +++++++++++---
app/services/newsletter.py | 42 ++++++++++++++++++++++++++++++++----
app/services/smtp_sender.py | 3 +++
app/templates/dashboard.html | 11 +++++++---
4 files changed, 62 insertions(+), 10 deletions(-)
diff --git a/app/main.py b/app/main.py
index 69b10d0..1cf0476 100644
--- a/app/main.py
+++ b/app/main.py
@@ -101,6 +101,7 @@ async def _run_scheduled_send_if_due() -> None:
display=DEFAULT_DISPLAY,
editor_tip="",
highlight_list=[],
+ contact_email=settings_snapshot.get("reply_to") or settings_snapshot.get("from_email", ""),
)
if gen["wiki_error"] or not gen["articles"]:
# Kein Versand ohne Inhalt; erneuter Versuch beim nächsten Intervall.
@@ -296,6 +297,7 @@ async def _generate_newsletter(
display,
editor_tip: str,
highlight_list: list[str],
+ contact_email: str = "",
) -> dict:
p = resolve_period(period_mode, days)
result = {
@@ -322,9 +324,9 @@ async def _generate_newsletter(
"articles_new": new_articles,
"articles_edited": edited_articles,
"subject": create_subject(p["month_label"], p["days"]),
- "plain_text": create_plain_text(filtered, p["days"], display, category, editor_tip, highlight_list, p["label"], prange, article_type),
- "raw_html": create_html(filtered, p["days"], display, category, editor_tip, highlight_list, p["label"], prange, article_type, p["month_label"]),
- "outlook_html": create_outlook_html(filtered, p["days"], display, category, editor_tip, highlight_list, p["label"], prange, article_type, p["month_label"]),
+ "plain_text": create_plain_text(filtered, p["days"], display, category, editor_tip, highlight_list, p["label"], prange, article_type, contact_email),
+ "raw_html": create_html(filtered, p["days"], display, category, editor_tip, highlight_list, p["label"], prange, article_type, p["month_label"], contact_email),
+ "outlook_html": create_outlook_html(filtered, p["days"], display, category, editor_tip, highlight_list, p["label"], prange, article_type, p["month_label"], contact_email),
}
)
except WikiFetchError as exc:
@@ -374,6 +376,8 @@ async def dashboard_generate(
article_type = "all"
display = parse_display_options(show_date, show_user, show_category)
highlight_list = parse_highlights(highlights)
+ smtp_cfg = get_smtp_settings(db)
+ contact_email = smtp_cfg["reply_to"] or smtp_cfg["from_email"]
gen = await _generate_newsletter(
period_mode=period,
@@ -383,6 +387,7 @@ async def dashboard_generate(
display=display,
editor_tip=editor_tip,
highlight_list=highlight_list,
+ contact_email=contact_email,
)
context = _base_context(request, current_user, db)
@@ -434,6 +439,8 @@ async def send_now(
article_type = "all"
highlight_list = parse_highlights(highlights)
days = max(1, min(days, 90))
+ smtp_cfg = get_smtp_settings(db)
+ contact_email = smtp_cfg["reply_to"] or smtp_cfg["from_email"]
gen = await _generate_newsletter(
period_mode=period,
@@ -443,6 +450,7 @@ async def send_now(
display=display,
editor_tip=editor_tip,
highlight_list=highlight_list,
+ contact_email=contact_email,
)
send_result: dict[str, str]
@@ -492,6 +500,7 @@ def update_smtp_settings(
username: str = Form(""),
password: str = Form(""),
from_email: str = Form(""),
+ reply_to: str = Form(""),
use_tls: str | None = Form(None),
recipients: str = Form(""),
schedule_enabled: str | None = Form(None),
@@ -513,6 +522,7 @@ def update_smtp_settings(
set_config(db, "smtp.username", username.strip())
set_config(db, "smtp.password", password)
set_config(db, "smtp.from_email", from_email.strip())
+ set_config(db, "smtp.reply_to", reply_to.strip())
set_config(db, "smtp.use_tls", "true" if use_tls == "true" else "false")
set_config(db, "smtp.recipients", recipients.strip())
diff --git a/app/services/newsletter.py b/app/services/newsletter.py
index 3cf481b..c31ab2a 100644
--- a/app/services/newsletter.py
+++ b/app/services/newsletter.py
@@ -203,6 +203,7 @@ def create_plain_text(
period_label: str | None = None,
period: tuple[str, str] | None = None,
article_type: str = "all",
+ contact_email: str = "",
) -> str:
display = display or DEFAULT_DISPLAY
new_articles, edited_articles = split_articles_by_type(articles)
@@ -250,7 +251,7 @@ def create_plain_text(
]
)
lines.extend(_plain_editor_tip(editor_tip))
- lines.append(_plain_footer(new_articles, edited_articles))
+ lines.append(_plain_footer(new_articles, edited_articles, contact_email))
return "\n".join(lines).strip()
if show_new:
@@ -267,7 +268,7 @@ def create_plain_text(
)
lines.append("")
lines.extend(_plain_editor_tip(editor_tip))
- lines.append(_plain_footer(new_articles, edited_articles))
+ lines.append(_plain_footer(new_articles, edited_articles, contact_email))
return "\n".join(lines).strip()
@@ -296,6 +297,7 @@ def create_html(
period: tuple[str, str] | None = None,
article_type: str = "all",
month_label: str | None = None,
+ contact_email: str = "",
) -> str:
display = display or DEFAULT_DISPLAY
new_articles, edited_articles = split_articles_by_type(articles)
@@ -334,6 +336,15 @@ def create_html(
f'Filter: Kategorie {escape(category.strip())}
'
)
+ if contact_email.strip():
+ ce = escape(contact_email.strip())
+ contact_html = (
+ f'Fragen oder ein Themenwunsch? Meldet euch gern beim '
+ f'Wiki-Team.'
+ )
+ else:
+ contact_html = "Fragen oder ein Themenwunsch? Meldet euch gern beim Wiki-Team."
+
return f"""
@@ -411,7 +422,7 @@ def create_html(
- Fragen oder ein Themenwunsch? Meldet euch gern beim Wiki-Team.
+ {contact_html}
Viele Grüße
Euer Thomas-Krenn-Wiki Team
|
@@ -679,6 +690,7 @@ def create_outlook_html(
period: tuple[str, str] | None = None,
article_type: str = "all",
month_label: str | None = None,
+ contact_email: str = "",
) -> str:
"""Word/Outlook-kompatibles HTML mit font-Tags und bgcolor (überlebt Einfügen in Outlook)."""
display = display or DEFAULT_DISPLAY
@@ -726,6 +738,19 @@ def create_outlook_html(
editor_tip_row = _outlook_editor_tip(editor_tip)
+ if contact_email.strip():
+ contact_inner = (
+ f'{_outlook_font("Fragen oder ein Themenwunsch? Meldet euch gern beim Wiki-Team: ", size="1")}'
+ f'{_outlook_link(contact_email.strip(), f"mailto:{contact_email.strip()}", color=OUTLOOK_ORANGE, bold=False)}'
+ )
+ contact_row = f"""
+ |
+ {contact_inner}
+ |
+
"""
+ else:
+ contact_row = ""
+
return f"""
@@ -785,6 +810,7 @@ def create_outlook_html(
{_outlook_cta(WIKI_HOME_URL, "Zum Thomas-Krenn-Wiki →")}
+ {contact_row}
|
{_outlook_font(f"Automatisch erstellter interner Newsletter · Nur für den Gebrauch bei {ORG_NAME}", color=OUTLOOK_MUTED, size="1")}
@@ -932,8 +958,15 @@ def _plain_item(idx: int, item: dict[str, Any], display: DisplayOptions) -> list
return lines
-def _plain_footer(new_articles: list[dict[str, Any]], edited_articles: list[dict[str, Any]]) -> str:
+def _plain_footer(
+ new_articles: list[dict[str, Any]],
+ edited_articles: list[dict[str, Any]],
+ contact_email: str = "",
+) -> str:
total = len(new_articles) + len(edited_articles)
+ contact_lines = []
+ if contact_email.strip():
+ contact_lines = [f"Fragen oder ein Themenwunsch? E-Mail an das Wiki-Team: {contact_email.strip()}", ""]
return "\n".join(
[
SUBLINE,
@@ -945,6 +978,7 @@ def _plain_footer(new_articles: list[dict[str, Any]], edited_articles: list[dict
"",
f"Wiki: {WIKI_HOME_URL}",
"",
+ *contact_lines,
SUBLINE,
"Dieser Newsletter wurde automatisch erstellt und ist nur für den internen",
f"Gebrauch bei {ORG_NAME} bestimmt.",
diff --git a/app/services/smtp_sender.py b/app/services/smtp_sender.py
index 585656a..bc4b890 100644
--- a/app/services/smtp_sender.py
+++ b/app/services/smtp_sender.py
@@ -18,6 +18,7 @@ def get_smtp_settings(db: Session) -> dict[str, str]:
"username": get_config(db, "smtp.username", ""),
"password": get_config(db, "smtp.password", ""),
"from_email": get_config(db, "smtp.from_email", ""),
+ "reply_to": get_config(db, "smtp.reply_to", ""),
"use_tls": get_config(db, "smtp.use_tls", "true"),
"recipients": get_config(db, "smtp.recipients", ""),
# Zeitplan
@@ -91,6 +92,8 @@ def send_newsletter(
msg["Subject"] = subject
msg["From"] = settings["from_email"]
msg["To"] = ", ".join(recipients)
+ if settings.get("reply_to"):
+ msg["Reply-To"] = settings["reply_to"]
try:
port = int(settings["port"])
diff --git a/app/templates/dashboard.html b/app/templates/dashboard.html
index c468cc7..5390ddd 100644
--- a/app/templates/dashboard.html
+++ b/app/templates/dashboard.html
@@ -253,9 +253,14 @@
-
+
+
+
+
|