diff --git a/hifi-src/src/pages/admin/settings/EmailSettings.jsx b/hifi-src/src/pages/admin/settings/EmailSettings.jsx
index 686bf8f..03c0ebe 100644
--- a/hifi-src/src/pages/admin/settings/EmailSettings.jsx
+++ b/hifi-src/src/pages/admin/settings/EmailSettings.jsx
@@ -58,6 +58,8 @@ export default function EmailSettings() {
const [testBusy, setTestBusy] = useState(false);
const [testError, setTestError] = useState('');
const [testSuccess, setTestSuccess] = useState('');
+ const [testWarning, setTestWarning] = useState('');
+ const [testLog, setTestLog] = useState(null);
useEffect(() => {
api
@@ -95,9 +97,13 @@ export default function EmailSettings() {
setTestBusy(true);
setTestError('');
setTestSuccess('');
+ setTestWarning('');
+ setTestLog(null);
try {
const res = await api.post('/settings/mail/test', form);
- setTestSuccess(`Testmail gesendet an ${res.sent_to}.`);
+ setTestSuccess(`Testmail gesendet an ${res.sent_to}. Der Server hat die Mail angenommen - prüfe auch den Spam-Ordner, das ist noch keine Garantie für die Zustellung.`);
+ setTestWarning(res.warning || '');
+ setTestLog(res.smtp_log || null);
} catch (err) {
setTestError(err.message);
} finally {
@@ -201,8 +207,13 @@ export default function EmailSettings() {
- {testError &&
{testError}
}
+ {testError &&
{testError}
}
{testSuccess &&
{testSuccess}
}
+ {testWarning && (
+
+ {testWarning}
+
+ )}
+ {testLog && testLog.length > 0 && (
+
+ SMTP-Protokoll anzeigen
+
+ {testLog.join('\n')}
+
+
+ )}
diff --git a/hifi/api/src/Controllers/MailSettingsController.php b/hifi/api/src/Controllers/MailSettingsController.php
index 315707c..488df9e 100644
--- a/hifi/api/src/Controllers/MailSettingsController.php
+++ b/hifi/api/src/Controllers/MailSettingsController.php
@@ -111,24 +111,42 @@ class MailSettingsController
Http::error('Empfaenger-E-Mail (Benachrichtigungs- oder Absenderadresse) ist ungueltig', 422);
}
+ $username = trim($body['mail_username'] ?? '');
+ $debugLog = [];
+
try {
$mail = Mailer::build([
'host' => $host,
'port' => $body['mail_port'] ?? 587,
- 'username' => trim($body['mail_username'] ?? ''),
+ 'username' => $username,
'password' => $password,
'encryption' => trim($body['mail_encryption'] ?? '') ?: 'tls',
'from_email' => $fromEmail,
'from_name' => trim($body['mail_from_name'] ?? '') ?: 'HifiPlanet',
]);
+ // Volles SMTP-Protokoll mitschneiden, damit bei "Verbindung ok, aber nichts kommt an"
+ // sichtbar wird, was der Server nach dem DATA-Befehl tatsaechlich geantwortet hat
+ // (z.B. eine 250-Bestaetigung, obwohl die Mail spaeter serverseitig verworfen wird).
+ $mail->SMTPDebug = 2;
+ $mail->Debugoutput = function ($str) use (&$debugLog) {
+ $debugLog[] = trim(preg_replace('/\s+/', ' ', $str));
+ };
$mail->addAddress($target);
$mail->Subject = 'Testmail von HifiPlanet';
$mail->Body = "Diese Testmail bestaetigt, dass deine SMTP-Einstellungen funktionieren.";
$mail->send();
} catch (\Throwable $e) {
- Http::error('Test fehlgeschlagen: ' . $e->getMessage(), 422);
+ Http::error('Test fehlgeschlagen: ' . $e->getMessage() . "\n\nSMTP-Protokoll:\n" . implode("\n", $debugLog), 422);
}
- Http::send(['ok' => true, 'sent_to' => $target]);
+ $warning = null;
+ if ($username !== '' && strcasecmp($username, $fromEmail) !== 0) {
+ $warning = 'Hinweis: Absender-E-Mail ("' . $fromEmail . '") und Benutzername ("' . $username . '") sind '
+ . 'unterschiedlich. Viele Mail-Provider akzeptieren die Mail dann zwar (siehe SMTP-Protokoll), '
+ . 'verwerfen sie aber im Anschluss ohne Fehlermeldung. Am sichersten ist es, die Absender-E-Mail '
+ . 'identisch zum SMTP-Benutzernamen zu setzen.';
+ }
+
+ Http::send(['ok' => true, 'sent_to' => $target, 'warning' => $warning, 'smtp_log' => $debugLog]);
}
}