{"record":{"id":"fa4244e149115418","repo":"passbolt/passbolt_api","slug":"could-not-validate-the-smtp-settings","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/SmtpSettingsGetService.php","lineNumber":64,"sourceCode":"    {\n        $this->passboltFileName = $passboltFileName;\n    }\n\n    /**\n     * Read SMTP settings in the DB, or in file.\n     * Validates the setting and return them\n     *\n     * @return array\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     */\n    public function getSettings(): array\n    {\n        $form = new EmailConfigurationForm();\n        $data = $this->readConfigInDbOrFile();\n\n        if (!$form->execute($data)) {\n            throw new FormValidationException(__('Could not validate the smtp settings.'), $form);\n        }\n\n        $allowedFields = array_merge([\n            'source', 'id', 'created', 'modified', 'created_by', 'modified_by',\n        ], SmtpSettingsSetService::SMTP_SETTINGS_ALLOWED_FIELDS);\n\n        return $this->sanitizeData($form->getData(), $allowedFields);\n    }\n\n    /**\n     * @return array\n     * @throws \\Cake\\Http\\Exception\\InternalErrorException if the data in the DB cannot be decrypted\n     */\n    protected function readConfigInDbOrFile(): array\n    {\n        return $this->readConfigInDb() ?? $this->readConfigInFile();\n    }\n","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltCe/SmtpSettings/src/Service/SmtpSettingsGetService.php#L46-L82","documentation":"Thrown by SmtpSettingsGetService::getSettings when the merged SMTP settings data (from DB, file, or env) fails validation against EmailConfigurationForm. A FormValidationException carrying the form errors is raised. This service validates the effective SMTP configuration before returning it to the check/test endpoints.","triggerScenarios":"Calling GET /smtp-settings.json (or the service's check/test flows) when the combined config from config/passbolt.php, env vars, or DB has invalid values — e.g. invalid email in sender, bad port, missing required fields like host or sender_email.","commonSituations":"Email settings defined via environment variables (EMAIL_DEFAULT_FROM etc.) with malformed addresses; passbolt.php email config partially defined; DB settings that predate new validation rules; mixing file and DB sources produces an invalid merge.","solutions":["Inspect the FormValidationException errors to identify which field fails (the form errors are attached to the exception).","Fix the source configuration: correct EMAIL_DEFAULT_FROM/EMAIL_TRANSPORT env vars or the email block in config/passbolt.php.","Re-save SMTP settings through the API so a valid, complete record is stored in the DB.","If multiple sources (file + env + DB) conflict, align them so the merged data is valid."],"exampleFix":"// before (env var with invalid email)\nEMAIL_DEFAULT_FROM=\"passbolt@invalid\"\n\n// after\nEMAIL_DEFAULT_FROM=\"no-reply@mycompany.com\"","handlingStrategy":"try-catch","validationCode":"$form = new EmailConfigurationForm();\n$data = ['sender_email' => env('EMAIL_DEFAULT_FROM'), 'host' => env('EMAIL_HOST'), ...];\nif (!$form->check($data)) {\n    // fix env/file config before calling getSettings\n}","typeGuard":null,"tryCatchPattern":"try {\n    $settings = $getService->getSettings();\n} catch (FormValidationException $e) {\n    $errors = $e->getForm()->getErrors(); // correct the failing field in DB/file/env\n}","preventionTips":["Validate EMAIL_* environment variables when provisioning servers.","Avoid partial email blocks in config/passbolt.php.","Prefer storing settings via the API so only validated data exists.","After upgrades, re-check SMTP settings since validation may have tightened."],"tags":["smtp","validation","configuration","cakephp"],"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"}