nopSolutions/nopCommerce · warning · NopException

Enter test email address

Error message

Enter test email address

What it means

Thrown in the EmailAccount test-email action when model.SendTestEmailTo is null or whitespace. NOTE: this throw is effectively dead code for empty input — an earlier guard (if (!CommonHelper.IsValidEmail(model.SendTestEmailTo))) catches empty/whitespace first and returns a 'wrong email' notification before the try block is reached. The NopException can only fire if IsValidEmail somehow passes a whitespace value, which the standard validator does not permit. It is caught and shown via ErrorNotification.

Source

Thrown at src/Presentation/Nop.Web/Areas/Admin/Controllers/EmailAccountController.cs:289

    [FormValueRequired("sendtestemail")]
    [CheckPermission(StandardPermission.Configuration.MANAGE_EMAIL_ACCOUNTS)]
    public virtual async Task<IActionResult> SendTestEmail(EmailAccountModel model)
    {
        //try to get an email account with the specified id
        var emailAccount = await _emailAccountService.GetEmailAccountByIdAsync(model.Id);
        if (emailAccount == null)
            return RedirectToAction("List");

        if (!CommonHelper.IsValidEmail(model.SendTestEmailTo))
        {
            _notificationService.ErrorNotification(await _localizationService.GetResourceAsync("Admin.Common.WrongEmail"));
            return View(await _emailAccountModelFactory.PrepareEmailAccountModelAsync(model, emailAccount, true));
        }

        try
        {
            if (string.IsNullOrWhiteSpace(model.SendTestEmailTo))
                throw new NopException("Enter test email address");
            var store = await _storeContext.GetCurrentStoreAsync();
            var subject = store.Name + ". Testing email functionality.";
            var body = "Email works fine.";
            await _emailSender.SendEmailAsync(emailAccount, subject, body, emailAccount.Email, emailAccount.DisplayName, model.SendTestEmailTo, null);

            _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Configuration.EmailAccounts.SendTestEmail.Success"));

            return RedirectToAction("Edit", new { id = emailAccount.Id });
        }
        catch (Exception exc)
        {
            _notificationService.ErrorNotification(exc.Message);
        }

        //prepare model
        model = await _emailAccountModelFactory.PrepareEmailAccountModelAsync(model, emailAccount, true);

        //if we got this far, something failed, redisplay form

View on GitHub (pinned to 64bdf2ff08)

Solutions

  1. Provide a valid email address in the 'Send test email to' field before submitting.
  2. Ensure client-side validation (required attribute) is active on the test-email form.
  3. Consider reordering the checks: validate non-empty first, then format, so the error message is always accurate.
  4. Remove the redundant IsNullOrWhiteSpace throw or move it above the IsValidEmail guard to fix the dead-code/ordering smell.

Example fix

// before — IsValidEmail guard runs first, making the empty-check unreachable
if (!CommonHelper.IsValidEmail(model.SendTestEmailTo))
{ ... return View(...); }
try
{
    if (string.IsNullOrWhiteSpace(model.SendTestEmailTo))
        throw new NopException("Enter test email address");
    ...
}

// after — validate presence first, then format
if (string.IsNullOrWhiteSpace(model.SendTestEmailTo))
{
    _notificationService.ErrorNotification(await _localizationService.GetResourceAsync("Admin.Common.WrongEmail"));
    return View(await _emailAccountModelFactory.PrepareEmailAccountModelAsync(model, emailAccount, true));
}
if (!CommonHelper.IsValidEmail(model.SendTestEmailTo))
{ ... }
Defensive patterns

Strategy: validation

Validate before calling

// Validate presence and format before submitting the test email
if (string.IsNullOrWhiteSpace(model.SendTestEmailTo) || !CommonHelper.IsValidEmail(model.SendTestEmailTo))
{
    ModelState.AddModelError("SendTestEmailTo", "Enter a valid test email address.");
    return View(model);
}

Type guard

bool IsValidTestRecipient(string email) => !string.IsNullOrWhiteSpace(email) && CommonHelper.IsValidEmail(email);

Try / catch

// Action's try/catch shows exc.Message; but note the IsNullOrWhiteSpace throw is shadowed by the earlier IsValidEmail guard — reorder checks to make the message accurate.

Prevention

When it happens

Trigger: POST to EmailAccount test-email with SendTestEmailTo empty or whitespace — though in practice the preceding IsValidEmail guard intercepts this and returns 'Admin.Common.WrongEmail' instead, so the raw 'Enter test email address' message is rarely seen.

Common situations: Automated/form-less POST that bypasses client-side required-field validation; a future refactor that reorders or removes the IsValidEmail guard could make this branch live again.

Related errors


AI-assisted analysis of nopSolutions/nopCommerce@64bdf2ff08 (2026-08-13). Data as JSON: /api/errors/8bf437b5f98c62fe. Report an issue: GitHub.