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 formView on GitHub (pinned to 64bdf2ff08)
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.
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
- 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.
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
- You cannot delete this email account. At least one account i
- Recipient email is not valid
- Sender email is not valid
- Enter amount to refund
- Enter shipped date
AI-assisted analysis of nopSolutions/nopCommerce@64bdf2ff08 (2026-08-13).
Data as JSON: /api/errors/8bf437b5f98c62fe.
Report an issue: GitHub.