passbolt/passbolt_api · error · FormValidationException

Could not validate the smtp settings.

Error message

Could not validate the smtp settings.

What it means

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.

Solutions

  1. Inspect the FormValidationException errors to identify which field fails (the form errors are attached to the exception).
  2. Fix the source configuration: correct EMAIL_DEFAULT_FROM/EMAIL_TRANSPORT env vars or the email block in config/passbolt.php.
  3. Re-save SMTP settings through the API so a valid, complete record is stored in the DB.
  4. If multiple sources (file + env + DB) conflict, align them so the merged data is valid.

Example fix

// before (env var with invalid email)
EMAIL_DEFAULT_FROM="passbolt@invalid"

// after
EMAIL_DEFAULT_FROM="no-reply@mycompany.com"
Defensive patterns

Strategy: try-catch

Validate before calling

$form = new EmailConfigurationForm();
$data = ['sender_email' => env('EMAIL_DEFAULT_FROM'), 'host' => env('EMAIL_HOST'), ...];
if (!$form->check($data)) {
    // fix env/file config before calling getSettings
}

Try / catch

try {
    $settings = $getService->getSettings();
} catch (FormValidationException $e) {
    $errors = $e->getForm()->getErrors(); // correct the failing field in DB/file/env
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of passbolt/passbolt_api@31c1bbc10f (2026-09-17). Data as JSON: /api/errors/fa4244e149115418. Report an issue: GitHub.

Appendix: source

Thrown at plugins/PassboltCe/SmtpSettings/src/Service/SmtpSettingsGetService.php:64

    {
        $this->passboltFileName = $passboltFileName;
    }

    /**
     * Read SMTP settings in the DB, or in file.
     * Validates the setting and return them
     *
     * @return array
     * @throws \App\Error\Exception\FormValidationException if the data does not validate the EmailConfigurationForm
     * @throws \Cake\Http\Exception\InternalErrorException if the data in the DB cannot be decrypted
     */
    public function getSettings(): array
    {
        $form = new EmailConfigurationForm();
        $data = $this->readConfigInDbOrFile();

        if (!$form->execute($data)) {
            throw new FormValidationException(__('Could not validate the smtp settings.'), $form);
        }

        $allowedFields = array_merge([
            'source', 'id', 'created', 'modified', 'created_by', 'modified_by',
        ], SmtpSettingsSetService::SMTP_SETTINGS_ALLOWED_FIELDS);

        return $this->sanitizeData($form->getData(), $allowedFields);
    }

    /**
     * @return array
     * @throws \Cake\Http\Exception\InternalErrorException if the data in the DB cannot be decrypted
     */
    protected function readConfigInDbOrFile(): array
    {
        return $this->readConfigInDb() ?? $this->readConfigInFile();
    }

View on GitHub (pinned to 31c1bbc10f)