{"record":{"id":"329eb36c8c647d89","repo":"nopSolutions/nopCommerce","slug":"recipient-email-is-not-valid","errorCode":null,"errorMessage":"Recipient email is not valid","messagePattern":"Recipient email is not valid","errorType":"exception","errorClass":"NopException","httpStatus":null,"severity":"warning","filePath":"src/Presentation/Nop.Web/Areas/Admin/Controllers/GiftCardController.cs","lineNumber":216,"sourceCode":"    public virtual IActionResult GenerateCouponCode()\n    {\n        return Json(new { CouponCode = _giftCardService.GenerateGiftCardCode() });\n    }\n\n    [HttpPost, ActionName(\"Edit\")]\n    [FormValueRequired(\"notifyRecipient\")]\n    [CheckPermission(StandardPermission.Orders.GIFT_CARDS_CREATE_EDIT_DELETE)]\n    public virtual async Task<IActionResult> NotifyRecipient(GiftCardModel model)\n    {\n        //try to get a gift card with the specified id\n        var giftCard = await _giftCardService.GetGiftCardByIdAsync(model.Id);\n        if (giftCard == null)\n            return RedirectToAction(\"List\");\n\n        try\n        {\n            if (!CommonHelper.IsValidEmail(giftCard.RecipientEmail))\n                throw new NopException(\"Recipient email is not valid\");\n\n            if (!CommonHelper.IsValidEmail(giftCard.SenderEmail))\n                throw new NopException(\"Sender email is not valid\");\n\n            var languageId = 0;\n            var order = await _orderService.GetOrderByOrderItemAsync(giftCard.PurchasedWithOrderItemId ?? 0);\n\n            if (order != null)\n            {\n                var customerLang = await _languageService.GetLanguageByIdAsync(order.CustomerLanguageId) ?? (await _languageService.GetAllLanguagesAsync()).FirstOrDefault();\n                if (customerLang != null)\n                    languageId = customerLang.Id;\n            }\n            else\n            {\n                languageId = _localizationSettings.DefaultAdminLanguageId;\n            }\n","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Presentation/Nop.Web/Areas/Admin/Controllers/GiftCardController.cs#L198-L234","documentation":"Thrown in the GiftCard NotifyRecipient action when the persisted giftCard.RecipientEmail fails CommonHelper.IsValidEmail. Unlike most validation here, this validates data already stored on the gift card (not the posted form) — the recipient email was captured when the gift card was created or purchased. NopException, caught and shown as an error notification.","triggerScenarios":"POST to GiftCard/NotifyRecipient (with the notifyRecipient form value) for a gift card whose RecipientEmail column holds an invalid or empty email address.","commonSituations":"Gift cards created via migration/seed data without a valid recipient email; a checkout flow or custom integration that wrote a malformed recipient email; legacy gift cards created before email validation was enforced at creation time.","solutions":["Open the gift card record and correct the RecipientEmail to a valid address, then retry notification.","Audit how the gift card was created — fix the upstream creation/purchase flow to validate recipient email at write time.","Run a data check for gift cards with invalid RecipientEmail before bulk-notify operations.","If this recurs, add IsValidEmail validation in the gift-card creation/purchase path."],"exampleFix":"// before — notify fails because stored email is invalid\nthrow new NopException(\"Recipient email is not valid\");\n\n// after — validate and repair the gift card record before notifying\nif (!CommonHelper.IsValidEmail(giftCard.RecipientEmail))\n{\n    _notificationService.ErrorNotification(\"Recipient email on this gift card is invalid; please correct it first.\");\n    return RedirectToAction(\"Edit\", new { id = giftCard.Id });\n}","handlingStrategy":"validation","validationCode":"// Before notifying: validate the stored recipient email\nif (!CommonHelper.IsValidEmail(giftCard.RecipientEmail))\n{\n    _notificationService.ErrorNotification(\"Recipient email on this gift card is invalid; correct it before notifying.\");\n    return RedirectToAction(\"Edit\", new { id = giftCard.Id });\n}","typeGuard":"bool HasValidRecipientEmail(GiftCard gc) => CommonHelper.IsValidEmail(gc?.RecipientEmail);","tryCatchPattern":"// The NotifyRecipient try/catch already shows exc.Message; pre-validate the stored email to avoid the error entirely.","preventionTips":["Validate recipient email at gift-card creation/purchase time.","Before bulk notify, filter gift cards whose RecipientEmail is invalid.","Run a data-quality query on legacy gift cards imported without email checks."],"tags":["nopcommerce","admin","gift-card","email","validation","stored-data"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}