Fix: Unable to reset email settings (#6963)

This commit is contained in:
Nicolas Dorier
2025-10-23 17:29:42 +09:00
committed by GitHub
parent 02adde7fd5
commit 42490c389d
2 changed files with 13 additions and 22 deletions

View File

@@ -79,8 +79,6 @@ public class UIStoresEmailController(
{
ModelState.AddModelError("Settings.From", StringLocalizer["Invalid email"]);
}
if (!ModelState.IsValid)
return View(model);
}
var storeBlob = store.GetStoreBlob();
@@ -88,6 +86,9 @@ public class UIStoresEmailController(
if (model is { IsCustomSMTP: true, Settings: { Password: null } })
model.Settings.Password = currentSettings?.Password;
if (!ModelState.IsValid && command is not ("ResetPassword" or "mailpit"))
return View(model);
if (command == "Test")
{
try

View File

@@ -61,27 +61,17 @@ namespace BTCPayServer.Services.Mails
{
return MailboxAddressValidator.IsMailboxAddress(From)
&& !string.IsNullOrWhiteSpace(Server)
&& Port != null;
&& Port != null
&& !string.IsNullOrWhiteSpace(From)
&& MailboxAddressValidator.IsMailboxAddress(From);
}
public void Validate(string prefixKey, ModelStateDictionary modelState)
{
if (string.IsNullOrWhiteSpace(From))
{
modelState.AddModelError($"{prefixKey}{nameof(From)}", new RequiredAttribute().FormatErrorMessage(nameof(From)));
}
if (!MailboxAddressValidator.IsMailboxAddress(From))
if (!string.IsNullOrEmpty(From) && !MailboxAddressValidator.IsMailboxAddress(From))
{
modelState.AddModelError($"{prefixKey}{nameof(From)}", MailboxAddressAttribute.ErrorMessageConst);
}
if (string.IsNullOrWhiteSpace(Server))
{
modelState.AddModelError($"{prefixKey}{nameof(Server)}", new RequiredAttribute().FormatErrorMessage(nameof(Server)));
}
if (Port is null)
{
modelState.AddModelError($"{prefixKey}{nameof(Port)}", new RequiredAttribute().FormatErrorMessage(nameof(Port)));
}
}
public MimeMessage CreateMailMessage(MailboxAddress to, string subject, string message, bool isHtml) =>