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:
@@ -2042,7 +2042,7 @@ def email_settings(request):
|
|||||||
}
|
}
|
||||||
|
|
||||||
elif action == "test_smtp_send":
|
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
|
from django.utils import timezone
|
||||||
|
|
||||||
test_email = request.POST.get("test_email", "").strip()
|
test_email = request.POST.get("test_email", "").strip()
|
||||||
@@ -2079,19 +2079,43 @@ def email_settings(request):
|
|||||||
fail_silently=False,
|
fail_silently=False,
|
||||||
)
|
)
|
||||||
now = timezone.now().strftime("%d.%m.%Y %H:%M")
|
now = timezone.now().strftime("%d.%m.%Y %H:%M")
|
||||||
msg = EmailMessage(
|
text_body = (
|
||||||
subject=f"[vHTV-Stiftung] SMTP-Test ({now})",
|
|
||||||
body=(
|
|
||||||
f"Dies ist eine Test-E-Mail der Stiftungsverwaltung.\n\n"
|
f"Dies ist eine Test-E-Mail der Stiftungsverwaltung.\n\n"
|
||||||
f"Zeitpunkt: {now}\n"
|
f"Zeitpunkt: {now}\n"
|
||||||
f"SMTP-Server: {host}:{port}\n"
|
f"SMTP-Server: {host}:{port}\n"
|
||||||
f"Absender: {from_email}\n\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."
|
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>✔ 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 • Raesfelder Str. 3 • 46499 Hamminkeln</div>'
|
||||||
|
'</div></body></html>'
|
||||||
|
)
|
||||||
|
msg = EmailMultiAlternatives(
|
||||||
|
subject=f"[vHTV-Stiftung] SMTP-Test ({now})",
|
||||||
|
body=text_body,
|
||||||
from_email=from_email,
|
from_email=from_email,
|
||||||
to=[test_email],
|
to=[test_email],
|
||||||
connection=connection,
|
connection=connection,
|
||||||
)
|
)
|
||||||
|
msg.attach_alternative(html_body, "text/html")
|
||||||
msg.send()
|
msg.send()
|
||||||
test_result = {
|
test_result = {
|
||||||
"success": True,
|
"success": True,
|
||||||
|
|||||||
@@ -23,6 +23,46 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
<!-- Test-E-Mail senden (prominent) -->
|
||||||
|
<div class="card mb-4 border-primary">
|
||||||
|
<div class="card-header bg-primary text-white">
|
||||||
|
<h3 class="card-title mb-0">
|
||||||
|
<i class="fas fa-paper-plane me-1"></i>
|
||||||
|
Test-E-Mail senden
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<p class="text-muted small mb-3">
|
||||||
|
Sendet eine echte Test-E-Mail (HTML + Text) an die angegebene Adresse, um den vollständigen Versandweg zu prüfen.
|
||||||
|
</p>
|
||||||
|
<form method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
<div class="input-group">
|
||||||
|
<input type="email"
|
||||||
|
class="form-control"
|
||||||
|
id="test_email_top"
|
||||||
|
name="test_email"
|
||||||
|
placeholder="empfaenger@example.de"
|
||||||
|
value="{{ request.POST.test_email|default:'' }}"
|
||||||
|
required>
|
||||||
|
<button type="submit" name="action" value="test_smtp_send" class="btn btn-primary">
|
||||||
|
<i class="fas fa-paper-plane me-1"></i> Senden
|
||||||
|
</button>
|
||||||
|
{% if request.user.email %}
|
||||||
|
<button type="button" class="btn btn-outline-secondary" onclick="document.getElementById('test_email_top').value='{{ request.user.email }}'" title="Eigene E-Mail-Adresse einfügen">
|
||||||
|
<i class="fas fa-user me-1"></i> An mich
|
||||||
|
</button>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% if request.user.email %}
|
||||||
|
<div class="form-text">Ihre Adresse: <code>{{ request.user.email }}</code></div>
|
||||||
|
{% else %}
|
||||||
|
<div class="form-text text-warning"><i class="fas fa-exclamation-triangle me-1"></i>Kein E-Mail in Ihrem Benutzerprofil hinterlegt. Bitte Adresse manuell eingeben.</div>
|
||||||
|
{% endif %}
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- IMAP Section -->
|
<!-- IMAP Section -->
|
||||||
<div class="card mb-4">
|
<div class="card mb-4">
|
||||||
<div class="card-header d-flex justify-content-between align-items-center">
|
<div class="card-header d-flex justify-content-between align-items-center">
|
||||||
@@ -178,24 +218,6 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr>
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="test_email" class="form-label">
|
|
||||||
<strong>Test-E-Mail senden</strong>
|
|
||||||
</label>
|
|
||||||
<div class="form-text mb-1">Sendet eine echte Test-E-Mail an die angegebene Adresse, um den vollständigen Versandweg zu prüfen.</div>
|
|
||||||
<div class="input-group">
|
|
||||||
<input type="email"
|
|
||||||
class="form-control"
|
|
||||||
id="test_email"
|
|
||||||
name="test_email"
|
|
||||||
placeholder="empfaenger@example.de"
|
|
||||||
value="{{ request.POST.test_email|default:'' }}">
|
|
||||||
<button type="submit" name="action" value="test_smtp_send" class="btn btn-outline-success">
|
|
||||||
<i class="fas fa-paper-plane me-1"></i> Test senden
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user