Improve email test: prominent card, HTML email, 'An mich' button

- Move test email form to a standalone card at the top of the page
  (was buried at the bottom of SMTP settings)
- Add 'An mich' button that fills in the logged-in user's email
- Send HTML + plain text test email (multi-alternative) styled like
  actual Stiftung emails, instead of plain text only
- Include diagnostic info (SMTP server, sender, user) in test email

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
SysAdmin Agent
2026-03-21 21:07:36 +00:00
parent 0e129ae56a
commit 59e05856b4
2 changed files with 73 additions and 27 deletions

View File

@@ -2042,7 +2042,7 @@ def email_settings(request):
}
elif action == "test_smtp_send":
from django.core.mail import EmailMessage, get_connection
from django.core.mail import EmailMultiAlternatives, get_connection
from django.utils import timezone
test_email = request.POST.get("test_email", "").strip()
@@ -2079,19 +2079,43 @@ def email_settings(request):
fail_silently=False,
)
now = timezone.now().strftime("%d.%m.%Y %H:%M")
msg = EmailMessage(
text_body = (
f"Dies ist eine Test-E-Mail der Stiftungsverwaltung.\n\n"
f"Zeitpunkt: {now}\n"
f"SMTP-Server: {host}:{port}\n"
f"Absender: {from_email}\n"
f"Gesendet von: {request.user.get_full_name() or request.user.username}\n\n"
f"Wenn Sie diese E-Mail erhalten, funktioniert der E-Mail-Versand korrekt."
)
html_body = (
'<!DOCTYPE html><html lang="de"><head><meta charset="UTF-8"></head><body>'
'<div style="max-width:600px;margin:32px auto;font-family:Arial,sans-serif;'
'border-radius:8px;overflow:hidden;box-shadow:0 2px 8px rgba(0,0,0,0.08);">'
'<div style="background:#1a3a5c;color:#fff;padding:28px 32px 20px;">'
'<h1 style="margin:0 0 4px;font-size:20px;">van Hees-Theyssen-Vogel\'sche Stiftung</h1>'
'<p style="margin:0;font-size:13px;opacity:0.8;">SMTP-Test</p></div>'
'<div style="padding:28px 32px;">'
'<p style="line-height:1.6;">Dies ist eine <strong>Test-E-Mail</strong> der Stiftungsverwaltung.</p>'
'<div style="background:#f0f6ff;border:1px solid #b0cce8;border-radius:6px;padding:16px 20px;margin:20px 0;">'
f'<p style="margin:0 0 8px;"><strong>Zeitpunkt:</strong> {now}</p>'
f'<p style="margin:0 0 8px;"><strong>SMTP-Server:</strong> {host}:{port}</p>'
f'<p style="margin:0 0 8px;"><strong>Absender:</strong> {from_email}</p>'
f'<p style="margin:0;"><strong>Gesendet von:</strong> {request.user.get_full_name() or request.user.username}</p>'
'</div>'
'<p style="line-height:1.6;color:#28a745;"><strong>&#10004; E-Mail-Versand funktioniert korrekt.</strong></p>'
'</div>'
'<div style="background:#f0f0f0;padding:16px 32px;font-size:12px;color:#777;border-top:1px solid #e0e0e0;">'
'van Hees-Theyssen-Vogel\'sche Stiftung &bull; Raesfelder Str. 3 &bull; 46499 Hamminkeln</div>'
'</div></body></html>'
)
msg = EmailMultiAlternatives(
subject=f"[vHTV-Stiftung] SMTP-Test ({now})",
body=(
f"Dies ist eine Test-E-Mail der Stiftungsverwaltung.\n\n"
f"Zeitpunkt: {now}\n"
f"SMTP-Server: {host}:{port}\n"
f"Absender: {from_email}\n\n"
f"Wenn Sie diese E-Mail erhalten, funktioniert der E-Mail-Versand korrekt."
),
body=text_body,
from_email=from_email,
to=[test_email],
connection=connection,
)
msg.attach_alternative(html_body, "text/html")
msg.send()
test_result = {
"success": True,