{"record":{"id":"64a062fb5702b282","repo":"nopSolutions/nopCommerce","slug":"default-email-account-cannot-be-loaded-64a062","errorCode":null,"errorMessage":"Default email account cannot be loaded","messagePattern":"Default email account cannot be loaded","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"src/Libraries/Nop.Services/Installation/InstallRequiredData.cs","lineNumber":741,"sourceCode":"                    DisplayName = \"Store name\",\n                    Host = \"smtp.mail.com\",\n                    Port = 25,\n                    Username = \"123\",\n                    Password = \"123\",\n                    EnableSsl = false\n                }\n            };\n\n        await _dataProvider.BulkInsertEntitiesAsync(emailAccounts);\n    }\n\n    /// <summary>\n    /// Installs a default message templates\n    /// </summary>\n    /// <returns>A task that represents the asynchronous operation</returns>\n    protected virtual async Task InstallMessageTemplatesAsync()\n    {\n        var eaGeneral = await Table<EmailAccount>().FirstOrDefaultAsync() ?? throw new Exception(\"Default email account cannot be loaded\");\n\n        var messageTemplates = new List<MessageTemplate>\n            {\n                new() {\n                    Name = MessageTemplateSystemNames.BLOG_COMMENT_STORE_OWNER_NOTIFICATION,\n                    Subject = \"%Store.Name%. New blog comment.\",\n                    Body = $\"<p>{Environment.NewLine}<a href=\\\"%Store.URL%\\\">%Store.Name%</a>{Environment.NewLine}<br />{Environment.NewLine}<br />{Environment.NewLine}A new blog comment has been created for blog post \\\"%BlogComment.BlogPostTitle%\\\".{Environment.NewLine}</p>{Environment.NewLine}\",\n                    IsActive = true,\n                    EmailAccountId = eaGeneral.Id\n                },\n                new() {\n                    Name = MessageTemplateSystemNames.BACK_IN_STOCK_NOTIFICATION,\n                    Subject = \"%Store.Name%. Back in stock notification\",\n                    Body = $\"<p>{Environment.NewLine}<a href=\\\"%Store.URL%\\\">%Store.Name%</a>{Environment.NewLine}<br />{Environment.NewLine}<br />{Environment.NewLine}Hello %Customer.FullName%,{Environment.NewLine}<br />{Environment.NewLine}Product <a target=\\\"_blank\\\" href=\\\"%BackInStockSubscription.ProductUrl%\\\">%BackInStockSubscription.ProductName%</a> is in stock.{Environment.NewLine}</p>{Environment.NewLine}\",\n                    IsActive = true,\n                    EmailAccountId = eaGeneral.Id\n                },\n                new() {","sourceCodeStart":723,"sourceCodeEnd":759,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Libraries/Nop.Services/Installation/InstallRequiredData.cs#L723-L759","documentation":"Thrown by InstallMessageTemplatesAsync during initial data installation. Message templates need an EmailAccountId, so the installer grabs the first EmailAccount in the table. If the EmailAccounts table is empty, there is no account to reference, so installation cannot proceed. This signals the email-account seeding step (which normally runs before this) failed or was skipped.","triggerScenarios":"Running the nopCommerce installer where InstallEmailAccountsAsync has not inserted any EmailAccount before InstallMessageTemplatesAsync runs; a partially-seeded database where EmailAccounts were deleted/cleared mid-install.","commonSituations":"Re-running installation against a half-cleaned database; a custom installation order that omits email account seeding; a migration that emptied the EmailAccounts table.","solutions":["Run the full installer in its default order so InstallEmailAccountsAsync executes before message templates.","Reset the database to a clean state and reinstall from scratch.","Verify the EmailAccounts table has at least one row before triggering installation.","If customizing install steps, ensure email account seeding precedes message template seeding."],"exampleFix":"// before - templates installed before any email account exists\nawait InstallMessageTemplatesAsync();\n\n// after - seed accounts first\nawait InstallEmailAccountsAsync();\nawait InstallMessageTemplatesAsync();","handlingStrategy":"validation","validationCode":"// Confirm an email account exists before installing message templates\nif (!await Table<EmailAccount>().AnyAsync())\n    throw new InvalidOperationException(\"Seed an EmailAccount before installing message templates.\");","typeGuard":"// Ensure the table is non-empty as a precondition\nstatic async Task<bool> HasEmailAccountAsync(IRepository<EmailAccount> repo)\n    => await repo.Table.AnyAsync();","tryCatchPattern":"try { await InstallMessageTemplatesAsync(); }\ncatch (Exception ex) when (ex.Message == \"Default email account cannot be loaded\")\n{ /* seed email accounts then retry installation */ }","preventionTips":["Run the installer steps in their default order.","Always start installation from a clean database.","Do not truncate EmailAccounts mid-install."],"tags":["installation","email-account","seeding","nopcommerce"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}