nopSolutions/nopCommerce · error · NopException
Email is not valid.
Error message
Email is not valid.
What it means
Thrown by CommonHelper.EnsureSubscriberEmailOrThrow when the supplied email fails the RFC 5322 regex check (CommonHelper.IsValidEmail). It is the canonical guard used when a newsletter subscription is created or updated; the email is first trimmed and truncated to 255 chars, then must match the strict EMAIL_EXPRESSION regex. A NopException (not ArgumentException) is raised so the application's global exception filter can localize and display it.
Source
Thrown at src/Libraries/Nop.Core/CommonHelper.cs:42
/// Get email validation regex
/// </summary>
/// <returns>Regular expression</returns>
[GeneratedRegex(EMAIL_EXPRESSION, RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture, "en-US")]
public static partial Regex GetEmailRegex();
/// <summary>
/// Ensures the subscriber email or throw.
/// </summary>
/// <param name="email">The email.</param>
/// <returns></returns>
public static string EnsureSubscriberEmailOrThrow(string email)
{
var output = EnsureNotNull(email);
output = output.Trim();
output = EnsureMaximumLength(output, 255);
if (!IsValidEmail(output))
throw new NopException("Email is not valid.");
return output;
}
/// <summary>
/// Verifies that a string is in valid email format
/// </summary>
/// <param name="email">Email to verify</param>
/// <returns>true if the string is a valid email address and false if it's not</returns>
public static bool IsValidEmail(string email)
{
if (string.IsNullOrEmpty(email))
return false;
email = email.Trim();
return GetEmailRegex().IsMatch(email);
}
View on GitHub (pinned to 64bdf2ff08)
Solutions
- Validate the input with CommonHelper.IsValidEmail(email) BEFORE calling EnsureSubscriberEmailOrThrow, and surface a friendly validation message on false.
- Strip display-name syntax and surrounding angle brackets/punctuation (e.g. extract the part between < >) before validating.
- Reject or normalize whitespace-only and null submissions at the controller/UI layer so they never reach the helper.
- If importing bulk lists, run them through the same IsValidEmail filter and quarantine rejects rather than inserting directly.
Example fix
// before
var sub = CommonHelper.EnsureSubscriberEmailOrThrow(rawEmail);
// after
if (!CommonHelper.IsValidEmail(rawEmail?.Trim() ?? string.Empty))
return BadRequest("Please enter a valid email address.");
var sub = CommonHelper.EnsureSubscriberEmailOrThrow(rawEmail); Defensive patterns
Strategy: validation
Validate before calling
var clean = (email ?? string.Empty).Trim();
if (!CommonHelper.IsValidEmail(clean))
// reject before calling EnsureSubscriberEmailOrThrow
return;
var validated = CommonHelper.EnsureSubscriberEmailOrThrow(clean); Type guard
static bool IsSubscribableEmail(string email)
=> !string.IsNullOrWhiteSpace(email)
&& email.Trim().Length <= 255
&& CommonHelper.IsValidEmail(email.Trim()); Try / catch
try { var sub = CommonHelper.EnsureSubscriberEmailOrThrow(email); }
catch (NopException ex) when (ex.Message == "Email is not valid.")
{ /* show localized validation error, do not crash */ } Prevention
- Run IsValidEmail on raw input at the UI/API boundary before persisting a subscription.
- Normalize input (trim, strip display-name/angle brackets) before validation.
- For CSV imports, filter rows through IsValidEmail and quarantine failures.
When it happens
Trigger: Calling NewsLetterSubscriptionService / anywhere EnsureSubscriberEmailOrThrow(email) is invoked with a malformed address (missing '@', invalid TLD, embedded spaces, quoted-local-part the regex rejects, or a value that after trimming exceeds structural limits). Also fires if the caller passes an already-truncated string that breaks the local-part or domain.
Common situations: User pastes a typo'd address on the newsletter signup box; an integration feeds a display-name format like 'John Doe <j@x.com>' instead of the bare address; migration scripts importing legacy subscriber lists with unvalidated values; trailing/leading whitespace plus a stray comma from CSV import.
Related errors
- Recipient email is not valid
- Sender email is not valid
- {titleRequiredLocale} (localized, formatted with languageNam
- {textRequiredLocale} (localized, formatted with languageName
- Email cannot be null
AI-assisted analysis of nopSolutions/nopCommerce@64bdf2ff08 (2026-08-13).
Data as JSON: /api/errors/c776a530ef9493e9.
Report an issue: GitHub.