{"record":{"id":"01b2bd690f1803af","repo":"passbolt/passbolt_api","slug":"could-not-validate-the-smtp-settings-01b2bd","errorCode":null,"errorMessage":"Could not validate the smtp settings.","messagePattern":"Could not validate the smtp settings\\.","errorType":"validation","errorClass":"FormValidationException","httpStatus":400,"severity":"error","filePath":"plugins/PassboltCe/SmtpSettings/src/Service/SmtpSettingsTestEmailService.php","lineNumber":157,"sourceCode":"        if (!empty($this->smtpSettings['client_secret'])) {\n            $toReplace[] = $this->smtpSettings['client_secret'];\n            $replaceWith[] = $replaceMask;\n        }\n\n        return str_replace($toReplace, $replaceWith, $str);\n    }\n\n    /**\n     * @param array $data Data in the payload\n     * @return array\n     * @throws \\App\\Error\\Exception\\FormValidationException if the data passed do not validate the EmailConfigurationForm\n     */\n    public function validateAndGetSmtpSettings(array $data): array\n    {\n        $form = new EmailConfigurationForm();\n\n        if (!$form->execute($data, ['validate' => 'sendTestEmail'])) {\n            throw new FormValidationException(__('Could not validate the smtp settings.'), $form);\n        }\n\n        return (array)$form->getData();\n    }\n}\n","sourceCodeStart":139,"sourceCodeEnd":163,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltCe/SmtpSettings/src/Service/SmtpSettingsTestEmailService.php#L139-L163","documentation":"Thrown by SmtpSettingsTestEmailService::validateAndGetSmtpSettings when the settings used to send a test email fail EmailConfigurationForm validation with the 'sendTestEmail' ruleset. Before passbolt attempts an SMTP connection it validates hostname, port, sender, credentials and TLS mode; invalid input raises FormValidationException so the client receives field-level errors rather than a cryptic SMTP transport failure.","triggerScenarios":"POST /smtp/settings/test with a payload whose hostname is empty or malformed, port is non-numeric/out of range, sender_email is invalid, or missing username/password for an authenticated SMTP transport — e.g. testing before saving settings, or testing settings coming from a legacy/invalid config file.","commonSituations":"Admin enters the email address of the recipient but the form data sent still contains empty or stale SMTP host/port fields; testing file-based (config) settings that were hand-edited with a bad port or TLS value; migrating from file config to DB where old config lacks required fields the newer validation ruleset enforces; automation scripts calling the test endpoint with partial payloads.","solutions":["Inspect the form errors returned in the API response (FormValidationException exposes getForm()->getErrors()) and correct the failing fields in the test request payload","Ensure the payload includes all required SMTP fields: sender_name, sender_email, hostname, port, tls, username, password — matching what the settings page would submit","If testing file-based settings, fix the values in config/passbolt.php (passbolt.email.transports / SMTP settings) so they pass validation, then retry the test email","Use `passbolt send_test_email you@example.com` CLI to test connectivity with config-file settings, or re-save SMTP settings through the UI so validated data is stored before re-running the test"],"exampleFix":"// before\n$service->sendTestEmail($admin, ['email' => 'admin@example.com', 'hostname' => '', 'port' => 'smtp']);\n// after\n$service->sendTestEmail($admin, [\n    'email' => 'admin@example.com',\n    'sender_name' => 'Passbolt',\n    'sender_email' => 'no-reply@example.com',\n    'hostname' => 'smtp.example.com',\n    'port' => 587,\n    'tls' => true,\n    'username' => 'smtp-user',\n    'password' => 'smtp-pass',\n]);","handlingStrategy":"validation","validationCode":"$form = new \\Passbolt\\SmtpSettings\\Form\\EmailConfigurationForm();\nif (!$form->execute($data, ['validate' => 'sendTestEmail'])) {\n    $errors = $form->getErrors(); // resolve before calling sendTestEmail\n}","typeGuard":"function canSendTestEmail(array $data): bool\n{\n    return !empty($data['hostname'])\n        && is_numeric($data['port'] ?? null)\n        && filter_var($data['sender_email'] ?? '', FILTER_VALIDATE_EMAIL) !== false\n        && filter_var($data['email'] ?? '', FILTER_VALIDATE_EMAIL) !== false;\n}","tryCatchPattern":"try {\n    $this->SmtpSettingsTestEmailService->sendTestEmail($admin, $data);\n} catch (\\App\\Error\\Exception\\FormValidationException $e) {\n    $fieldErrors = $e->getForm()->getErrors();\n    // surface field errors to the admin UI instead of attempting SMTP\n}","preventionTips":["Save SMTP settings via the settings UI first, then send the test email with the same validated payload","Never submit the test endpoint with empty hostname/port; reuse the payload from the last successful save","For file-based config, run `passbolt send_test_email` CLI first — it surfaces validation and connection errors clearly","Validate emails (sender and recipient) with FILTER_VALIDATE_EMAIL and port with is_int/is_numeric before calling the API"],"tags":["validation","form","smtp-settings","test-email"],"backgroundTag":"schema-validation-failed","analyzedSha":"31c1bbc10f32808a607fa9bd81891e898779c0bc","analyzedAt":"2026-09-17T00:04:38.960Z","contentChangedAt":"2026-09-17T00:04:38.960Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}