Billionmail/BillionMail · error

You cannot create more than 5000 batches

Error message

You cannot create more than 5000 batches

What it means

BatchAddMailbox enforces a hard cap: req.Count may not exceed 5000 mailboxes per call. The guard returns before invoking mail_boxes.BatchAdd. It exists to protect the DB and Dovecot provisioning from unbounded bulk creation in one request.

Source

Thrown at core/internal/controller/mail_boxes/mail_boxes_v1_batch_add_mailbox.go:18

package mail_boxes

import (
	"billionmail-core/internal/consts"
	"billionmail-core/internal/service/public"
	"context"
	"fmt"

	"billionmail-core/api/mail_boxes/v1"
	"billionmail-core/internal/service/mail_boxes"
)

func (c *ControllerV1) BatchAddMailbox(ctx context.Context, req *v1.BatchAddMailboxReq) (res *v1.BatchAddMailboxRes, err error) {

	res = &v1.BatchAddMailboxRes{}

	if req.Count > 5000 {
		return nil, fmt.Errorf("You cannot create more than 5000 batches")
	}

	createdEmails, err := mail_boxes.BatchAdd(ctx, req.Domain, req.Quota, req.Count, req.Prefix, req.QuotaActive)
	if err != nil {
		return nil, err
	}

	successMsg := fmt.Sprintf("%d email accounts were successfully created", len(createdEmails))

	_ = public.WriteLog(ctx, public.LogParams{
		Type: consts.LOGTYPE.Mailboxes,
		Log:  "Batch email creation was successful",
		Data: req,
	})
	res.SetSuccess(successMsg)
	res.Data = createdEmails
	return res, nil
}

View on GitHub (pinned to fc36c76c05)

Solutions

  1. Split the request into chunks of at most 5000 and call BatchAddMailbox repeatedly.
  2. Lower req.Count to the actually needed number.
  3. Increase the limit in the controller only if provisioning infrastructure can handle it (requires code change).

Example fix

// before
{"domain":"example.com","count":12000}
// after
// 3 calls with count 5000, 5000, 2000
Defensive patterns

Strategy: validation

Validate before calling

const MAX_BATCH = 5000
if (!Number.isInteger(count) || count < 1 || count > MAX_BATCH) {
  throw new Error(`count must be between 1 and ${MAX_BATCH}`)
}

Try / catch

try {
  await api.batchAddMailbox({domain, count})
} catch (e) {
  if (String(e.message).includes('more than 5000')) {
    for (const chunk of chunkArray(requests, 5000)) await api.batchAddMailbox({domain, count: chunk})
  } else throw e
}

Prevention

When it happens

Trigger: Calling BatchAddMailbox with a count body field greater than 5000, e.g. {"count": 10000}.

Common situations: Bulk-provisioning a large organization in one request; a frontend mis-sending a default or sentinel value; automated scripts computing count from a full employee list.

Related errors


AI-assisted analysis of Billionmail/BillionMail@fc36c76c05 (2026-09-05). Data as JSON: /api/errors/c5e068cb36cf10aa. Report an issue: GitHub.