Halve of foute mailconfiguratie: host start, mail uit, een duidelijke Error-logregel
Eén bron (IMailAvailability) bepaalt of mail aan staat: SMTP-host gezet EN de hele mailconfiguratie geldig. Anders start de host gewoon, gebruikt de Null-verzender, meldt emailEnabled=false en logt eenmalig mail_configuration_invalid met de namen van de ontbrekende of ongeldige instellingen (nooit waarden of geheimen). Getest: halve config, elke soort fout, geen geheim in het log, volledige config werkt als voorheen, geen mailinstelling geeft geen enkele waarschuwing, alle verbruikers zien mail als uit. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,9 +10,19 @@ namespace SlpModularCms.Core.Email;
|
||||
public sealed class EmailOptionsValidator(IOptions<AppMailOptions> app) : IValidateOptions<EmailOptions>
|
||||
{
|
||||
public ValidateOptionsResult Validate(string? name, EmailOptions options)
|
||||
{
|
||||
var failures = Check(options, app.Value);
|
||||
return failures.Count == 0 ? ValidateOptionsResult.Success : ValidateOptionsResult.Fail(failures);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The problems of a mail configuration (setting names only, never values). Empty when mail is off (no host)
|
||||
/// or the configuration is valid.
|
||||
/// </summary>
|
||||
public static IReadOnlyList<string> Check(EmailOptions options, AppMailOptions appOptions)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(options.Smtp.Host))
|
||||
return ValidateOptionsResult.Success; // mail disabled
|
||||
return []; // mail disabled
|
||||
|
||||
var failures = new List<string>();
|
||||
|
||||
@@ -34,16 +44,16 @@ public sealed class EmailOptionsValidator(IOptions<AppMailOptions> app) : IValid
|
||||
failures.Add("Email:AllowedFromAddresses contains an invalid e-mail address.");
|
||||
}
|
||||
|
||||
var baseUrl = app.Value.PublicBaseUrl;
|
||||
var baseUrl = appOptions.PublicBaseUrl;
|
||||
if (!IsValidPublicBaseUrl(baseUrl))
|
||||
failures.Add("App:PublicBaseUrl must be an absolute https URL (http only for localhost) without a path.");
|
||||
if (!MailLanguages.IsSupported(app.Value.DefaultLanguage))
|
||||
if (!MailLanguages.IsSupported(appOptions.DefaultLanguage))
|
||||
failures.Add("App:DefaultLanguage must be 'nl' or 'en'.");
|
||||
|
||||
if (!string.IsNullOrEmpty(options.LogoUrl) && !IsValidLogoUrl(options.LogoUrl))
|
||||
failures.Add("Email:LogoUrl must be an https URL or a path starting with '/'.");
|
||||
|
||||
return failures.Count == 0 ? ValidateOptionsResult.Success : ValidateOptionsResult.Fail(failures);
|
||||
return failures;
|
||||
}
|
||||
|
||||
public static bool IsValidPublicBaseUrl(string? value)
|
||||
|
||||
Reference in New Issue
Block a user