{"record":{"id":"3324d8bf05d78343","repo":"passbolt/passbolt_api","slug":"could-not-validate-the-smtp-settings-found-in-database","errorCode":null,"errorMessage":"Could not validate the smtp settings found in database.","messagePattern":"Could not validate the smtp settings found in database\\.","errorType":"validation","errorClass":"FormValidationException","httpStatus":400,"severity":"error","filePath":"plugins/PassboltCe/SmtpSettings/src/Service/SmtpSettingsGetSettingsInDbService.php","lineNumber":54,"sourceCode":"     * @return array|null\n     * @throws \\App\\Error\\Exception\\FormValidationException if the data does not validate the EmailConfigurationForm\n     * @throws \\Cake\\Http\\Exception\\InternalErrorException if the data in the DB cannot be decrypted\n     * @throws \\Cake\\Database\\Exception\\MissingConnectionException if the database is not in place (this is the case during installation)\n     */\n    public function getSettings(): ?array\n    {\n        $form = new EmailConfigurationForm();\n        $data = $this->readConfigInDB();\n\n        if (is_null($data)) {\n            return null;\n        }\n\n        if (!$form->execute($data)) {\n            // An exception is thrown, the settings should not be consumed, but the source is appended for\n            // diagnostic purposes.\n            $form->set('source', SmtpSettingsGetService::SMTP_SETTINGS_SOURCE_DB);\n            throw new FormValidationException(__('Could not validate the smtp settings found in database.'), $form);\n        }\n\n        return $form->getData();\n    }\n\n    /**\n     * Reads SMTP in the organization settings table\n     *\n     * @return array|null\n     * @throws \\Cake\\Http\\Exception\\InternalErrorException if the data in the DB cannot be decrypted\n     */\n    protected function readConfigInDB(): ?array\n    {\n        /** @var \\App\\Model\\Table\\OrganizationSettingsTable $OrganizationSettings */\n        $OrganizationSettings = TableRegistry::getTableLocator()->get('OrganizationSettings');\n        try {\n            $settings = $OrganizationSettings->getByProperty(self::SMTP_SETTINGS_PROPERTY_NAME);\n        } catch (Throwable $e) {","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltCe/SmtpSettings/src/Service/SmtpSettingsGetSettingsInDbService.php#L36-L72","documentation":"Thrown by SmtpSettingsGetSettingsInDbService::getSettings when the SMTP settings stored in the database fail validation against EmailConfigurationForm. Before throwing, the form gets `source: 'database'` appended so diagnostics show which source was invalid; a FormValidationException is raised.","triggerScenarios":"Reading DB-stored SMTP settings (used by the smtp-settings get/test endpoints) where the stored record has invalid values: malformed sender email, out-of-range port, null/empty required fields such as host, or rows written by older versions with different schemas.","commonSituations":"Settings saved by an older passbolt version that current validation rejects; partial writes; manual DB edits to the smtp_settings/organization_settings record; corrupted records after failed saves.","solutions":["Read the validation errors attached to the FormValidationException; the `source` field will confirm the problem came from the DB record.","Re-save correct SMTP settings via POST /smtp-settings.json so a valid record replaces the bad one.","Fix or delete the offending DB row and fall back to file/env configuration temporarily.","After a passbolt upgrade, re-test SMTP settings since validation rules may have tightened."],"exampleFix":"// before (bad DB record)\n{ \"sender_email\": \"not-an-email\", \"port\": \"smtp\" }\n\n// after: re-save valid settings\nPOST /smtp-settings.json { \"sender_email\": \"no-reply@mycompany.com\", \"port\": 587, \"host\": \"smtp.mycompany.com\", ... }","handlingStrategy":"validation","validationCode":"$form = new EmailConfigurationForm();\n$stored = /* fetch DB row */;\nif (!$form->check($stored)) {\n    // repair or delete the DB row before invoking the get service\n}","typeGuard":null,"tryCatchPattern":"try {\n    $data = $inDbService->getSettings();\n} catch (FormValidationException $e) {\n    $form = $e->getForm();\n    Log::error('DB smtp settings invalid, source=' . $form->getData()['source'] ?? 'database');\n    // fall back to file/env settings\n}","preventionTips":["Only write SMTP settings via the validated API.","Never edit smtp settings rows manually in SQL.","Round-trip test (save then read) after passbolt upgrades.","Delete invalid rows to fall back to file/env config instead of leaving them in place."],"tags":["smtp","validation","database","configuration"],"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"}