nopSolutions/nopCommerce · warning · NopException

You cannot delete this email account. At least one account i

Error message

You cannot delete this email account. At least one account is required.

What it means

Thrown by EmailAccountService.DeleteEmailAccountAsync when the account being deleted is the only remaining one (GetAllEmailAccountsAsync().Count == 1). nopCommerce requires at least one email account because message templates and settings reference a default account; deleting the last one would leave dangling references and break email sending. The exception is a NopException surfaced to the admin UI.

Source

Thrown at src/Libraries/Nop.Services/Messages/EmailAccountService.cs:99

        emailAccount.DisplayName = CommonHelper.EnsureMaximumLength(emailAccount.DisplayName, 255);
        emailAccount.Host = CommonHelper.EnsureMaximumLength(emailAccount.Host, 255);
        emailAccount.Username = CommonHelper.EnsureMaximumLength(emailAccount.Username, 255);
        emailAccount.Password = CommonHelper.EnsureMaximumLength(emailAccount.Password, 255);

        await _emailAccountRepository.UpdateAsync(emailAccount);
    }

    /// <summary>
    /// Deletes an email account
    /// </summary>
    /// <param name="emailAccount">Email account</param>
    /// <returns>A task that represents the asynchronous operation</returns>
    public virtual async Task DeleteEmailAccountAsync(EmailAccount emailAccount)
    {
        ArgumentNullException.ThrowIfNull(emailAccount);

        if ((await GetAllEmailAccountsAsync()).Count == 1)
            throw new NopException("You cannot delete this email account. At least one account is required.");

        await _emailAccountRepository.DeleteAsync(emailAccount);
    }

    /// <summary>
    /// Gets an email account by identifier
    /// </summary>
    /// <param name="emailAccountId">The email account identifier</param>
    /// <returns>
    /// A task that represents the asynchronous operation
    /// The task result contains the email account
    /// </returns>
    public virtual async Task<EmailAccount> GetEmailAccountByIdAsync(int emailAccountId)
    {
        return await _emailAccountRepository.GetByIdAsync(emailAccountId, cache => default);
    }

    /// <summary>

View on GitHub (pinned to 64bdf2ff08)

Solutions

  1. Create at least one other EmailAccount before deleting the current last one.
  2. In admin, add a new account first, then delete the unwanted one.
  3. Guard UI/scripts: disable the delete action when the account list has a single entry.

Example fix

// before
await _emailAccountService.DeleteEmailAccountAsync(account);

// after - ensure more than one account exists before deleting
if ((await _emailAccountService.GetAllEmailAccountsAsync()).Count <= 1)
    return BadRequest("Create another email account before deleting this one.");
await _emailAccountService.DeleteEmailAccountAsync(account);
Defensive patterns

Strategy: validation

Validate before calling

// Block deletion of the last email account before calling the service
var accounts = await _emailAccountService.GetAllEmailAccountsAsync();
if (accounts.Count <= 1)
    return BadRequest("Create another email account before deleting this one.");
await _emailAccountService.DeleteEmailAccountAsync(account);

Type guard

static async Task<bool> CanDeleteAsync(IEmailAccountService svc)
    => (await svc.GetAllEmailAccountsAsync()).Count > 1;

Try / catch

try { await _emailAccountService.DeleteEmailAccountAsync(account); }
catch (NopException ex) when (ex.Message.Contains("At least one account is required"))
{ /* inform the user to create a replacement account first */ }

Prevention

When it happens

Trigger: Calling DeleteEmailAccountAsync on the last remaining EmailAccount; an admin attempting to delete the only configured email account.

Common situations: Admin cleaning up test accounts and deleting the last one; automation script that removes all email accounts; attempt to delete before creating a replacement.

Related errors


AI-assisted analysis of nopSolutions/nopCommerce@64bdf2ff08 (2026-08-13). Data as JSON: /api/errors/844931dfe54616b8. Report an issue: GitHub.