Billionmail/BillionMail · critical

Failed to create email

Error message

Failed to create email: %w

What it means

Top-level wrapper in BatchAdd: after the transaction closure runs, any error it returned is re-wrapped as 'Failed to create email: %w'. It indicates that the batch mailbox creation transaction did not complete — the real cause is always nested inside. If err is nil but nothing was created, error 325 is thrown instead.

Solutions

  1. Unwrap the error to find the root cause (look for 'Batch insert mailbox failed' or similar)
  2. Fix the underlying database/transaction issue identified by the wrapped error
  3. Retry the batch creation after resolving the cause
Defensive patterns

Strategy: try-catch

Try / catch

created, err := BatchAddMailbox(...)
if err != nil {
    var root = err
    for errors.Unwrap(root) != nil { root = errors.Unwrap(root) }
    log.Printf("batch create failed, root cause: %v", root)
}

Prevention

When it happens

Trigger: Any failure inside the BatchAdd transaction (e.g. error 323 batch insert failure) surfacing at the BatchAddMailbox call boundary.

Common situations: Bulk mailbox provisioning failing because of database errors, constraint conflicts, or transaction aborts.

Related errors


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

Appendix: source

Thrown at core/internal/service/mail_boxes/mail_boxes.go:367

				mb := mbs[i]
				sem <- struct{}{}
				go func(mb v1.Mailbox) {
					defer func() { <-sem }()
					_ = ensureMaildirAndQuotaFile(context.Background(), &mb)
				}(mb)
			}

			for i := 0; i < cap(sem); i++ {
				sem <- struct{}{}
			}
		}(mailboxes)

		return nil
	})

	if err != nil {

		return nil, fmt.Errorf("Failed to create email: %w", err)
	}

	if len(emailList) == 0 {
		return nil, fmt.Errorf("Failed to create any mailbox")
	}

	return emailList, nil
}

// AddImport
func AddImport(ctx context.Context, mailbox *v1.Mailbox) (err error) {

	if mailbox.PasswordEncode != "" {

		if mailbox.Password == "" {
			mailbox.Password, err = PasswdDecode(ctx, mailbox.PasswordEncode)
			if err != nil {
				err = fmt.Errorf("Decode password failed: %w", err)

View on GitHub (pinned to fc36c76c05)