{"record":{"id":"8bf437b5f98c62fe","repo":"nopSolutions/nopCommerce","slug":"enter-test-email-address","errorCode":null,"errorMessage":"Enter test email address","messagePattern":"Enter test email address","errorType":"exception","errorClass":"NopException","httpStatus":null,"severity":"warning","filePath":"src/Presentation/Nop.Web/Areas/Admin/Controllers/EmailAccountController.cs","lineNumber":289,"sourceCode":"    [FormValueRequired(\"sendtestemail\")]\n    [CheckPermission(StandardPermission.Configuration.MANAGE_EMAIL_ACCOUNTS)]\n    public virtual async Task<IActionResult> SendTestEmail(EmailAccountModel model)\n    {\n        //try to get an email account with the specified id\n        var emailAccount = await _emailAccountService.GetEmailAccountByIdAsync(model.Id);\n        if (emailAccount == null)\n            return RedirectToAction(\"List\");\n\n        if (!CommonHelper.IsValidEmail(model.SendTestEmailTo))\n        {\n            _notificationService.ErrorNotification(await _localizationService.GetResourceAsync(\"Admin.Common.WrongEmail\"));\n            return View(await _emailAccountModelFactory.PrepareEmailAccountModelAsync(model, emailAccount, true));\n        }\n\n        try\n        {\n            if (string.IsNullOrWhiteSpace(model.SendTestEmailTo))\n                throw new NopException(\"Enter test email address\");\n            var store = await _storeContext.GetCurrentStoreAsync();\n            var subject = store.Name + \". Testing email functionality.\";\n            var body = \"Email works fine.\";\n            await _emailSender.SendEmailAsync(emailAccount, subject, body, emailAccount.Email, emailAccount.DisplayName, model.SendTestEmailTo, null);\n\n            _notificationService.SuccessNotification(await _localizationService.GetResourceAsync(\"Admin.Configuration.EmailAccounts.SendTestEmail.Success\"));\n\n            return RedirectToAction(\"Edit\", new { id = emailAccount.Id });\n        }\n        catch (Exception exc)\n        {\n            _notificationService.ErrorNotification(exc.Message);\n        }\n\n        //prepare model\n        model = await _emailAccountModelFactory.PrepareEmailAccountModelAsync(model, emailAccount, true);\n\n        //if we got this far, something failed, redisplay form","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Presentation/Nop.Web/Areas/Admin/Controllers/EmailAccountController.cs#L271-L307","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Provide a valid email address in the 'Send test email to' field before submitting.","Ensure client-side validation (required attribute) is active on the test-email form.","Consider reordering the checks: validate non-empty first, then format, so the error message is always accurate.","Remove the redundant IsNullOrWhiteSpace throw or move it above the IsValidEmail guard to fix the dead-code/ordering smell."],"exampleFix":"// before — IsValidEmail guard runs first, making the empty-check unreachable\nif (!CommonHelper.IsValidEmail(model.SendTestEmailTo))\n{ ... return View(...); }\ntry\n{\n    if (string.IsNullOrWhiteSpace(model.SendTestEmailTo))\n        throw new NopException(\"Enter test email address\");\n    ...\n}\n\n// after — validate presence first, then format\nif (string.IsNullOrWhiteSpace(model.SendTestEmailTo))\n{\n    _notificationService.ErrorNotification(await _localizationService.GetResourceAsync(\"Admin.Common.WrongEmail\"));\n    return View(await _emailAccountModelFactory.PrepareEmailAccountModelAsync(model, emailAccount, true));\n}\nif (!CommonHelper.IsValidEmail(model.SendTestEmailTo))\n{ ... }","handlingStrategy":"validation","validationCode":"// Validate presence and format before submitting the test email\nif (string.IsNullOrWhiteSpace(model.SendTestEmailTo) || !CommonHelper.IsValidEmail(model.SendTestEmailTo))\n{\n    ModelState.AddModelError(\"SendTestEmailTo\", \"Enter a valid test email address.\");\n    return View(model);\n}","typeGuard":"bool IsValidTestRecipient(string email) => !string.IsNullOrWhiteSpace(email) && CommonHelper.IsValidEmail(email);","tryCatchPattern":"// 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.","preventionTips":["Add a client-side required+email validator on the test-recipient input.","Reorder server checks: non-empty first, then IsValidEmail.","Treat the 'Enter test email address' throw as dead code unless the guard ordering is fixed."],"tags":["nopcommerce","admin","email-account","validation","dead-code","ordering"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}