{"record":{"id":"f374945e4695ac29","repo":"nopSolutions/nopCommerce","slug":"email-account-could-not-be-loaded-f37494","errorCode":null,"errorMessage":"Email account could not be loaded","messagePattern":"Email account could not be loaded","errorType":"exception","errorClass":"NopException","httpStatus":null,"severity":"error","filePath":"src/Presentation/Nop.Web/Areas/Admin/Controllers/CampaignController.cs","lineNumber":77,"sourceCode":"        _emailAccountService = emailAccountService;\n        _localizationService = localizationService;\n        _notificationService = notificationService;\n        _newsLetterSubscriptionService = newsLetterSubscriptionService;\n        _permissionService = permissionService;\n        _storeContext = storeContext;\n        _storeService = storeService;\n        _workContext = workContext;\n    }\n\n    #endregion\n\n    #region Utilities\n\n    protected virtual async Task<EmailAccount> GetEmailAccountAsync(int emailAccountId)\n    {\n        return await _emailAccountService.GetEmailAccountByIdAsync(emailAccountId)\n               ?? await _emailAccountService.GetEmailAccountByIdAsync(_emailAccountSettings.DefaultEmailAccountId)\n               ?? throw new NopException(\"Email account could not be loaded\");\n    }\n\n    #endregion\n\n    #region Methods\n\n    public virtual IActionResult Index()\n    {\n        return RedirectToAction(\"List\");\n    }\n\n    [CheckPermission(StandardPermission.Promotions.CAMPAIGNS_VIEW)]\n    public virtual async Task<IActionResult> List()\n    {\n        //prepare model\n        var model = await _campaignModelFactory.PrepareCampaignSearchModelAsync(new CampaignSearchModel());\n\n        return View(model);","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Presentation/Nop.Web/Areas/Admin/Controllers/CampaignController.cs#L59-L95","documentation":"Thrown by CampaignController.GetEmailAccountAsync as a NopException after a two-stage fallback: first by the provided emailAccountId, then by EmailAccountSettings.DefaultEmailAccountId. If both resolve to null, sending a campaign is impossible and it throws. It is a configuration error — no usable email account exists for campaigns.","triggerScenarios":"Any campaign send/preview path that calls GetEmailAccountAsync when both the supplied emailAccountId and the configured DefaultEmailAccountId point at deleted/non-existent EmailAccount rows.","commonSituations":"Default email account was deleted but EmailAccountSettings.DefaultEmailAccountId still references it; fresh install where no email account was designated as default; multi-store email account misconfiguration.","solutions":["In Admin > Configuration > Email Accounts, create or designate a default email account and save the DefaultEmailAccountId.","Update the campaign's own EmailAccountId field to a valid account before sending.","Run a DB repair aligning EmailAccountSettings.DefaultEmailAccountId with an existing EmailAccount row."],"exampleFix":"// before\nreturn await _emailAccountService.GetEmailAccountByIdAsync(emailAccountId)\n       ?? await _emailAccountService.GetEmailAccountByIdAsync(_emailAccountSettings.DefaultEmailAccountId)\n       ?? throw new NopException(\"Email account could not be loaded\");\n\n// after (point at the actionable config)\nvar account = await _emailAccountService.GetEmailAccountByIdAsync(emailAccountId)\n            ?? await _emailAccountService.GetEmailAccountByIdAsync(_emailAccountSettings.DefaultEmailAccountId);\nif (account == null)\n    throw new NopException(\"Email account could not be loaded. Set a valid DefaultEmailAccountId in Configuration > Email Accounts.\");\nreturn account;\n","handlingStrategy":"validation","validationCode":"// Ensure a default email account is configured before any campaign send.\nvar defaultId = _emailAccountSettings.DefaultEmailAccountId;\nif (defaultId == 0 || await _emailAccountService.GetEmailAccountByIdAsync(defaultId) == null)\n    throw new NopException(\"Configure a default email account in Configuration > Email Accounts before sending campaigns.\");","typeGuard":"static async Task<bool> DefaultEmailAccountIsUsable(IEmailAccountService svc, int id)\n    => id != 0 && await svc.GetEmailAccountByIdAsync(id) is not null;","tryCatchPattern":"try { var account = await GetEmailAccountAsync(emailAccountId); }\ncatch (NopException ex) when (ex.Message == \"Email account could not be loaded\")\n{\n    _notificationService.ErrorNotification(\"No email account configured. Set a default in Configuration > Email Accounts.\");\n    return RedirectToAction(\"List\");\n}","preventionTips":["Always designate a default email account after install.","When deleting an email account, reassign DefaultEmailAccountId first.","Validate the configured default at startup or before campaign send."],"tags":["nopcommerce","campaign","email-account","configuration","nopexception"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}