larksuite/cli · error

emlbuilder: From address is required

Error message

emlbuilder: From address is required

What it means

Build() requires a From address; it returns this error when the builder's from.Address is empty. A RFC 5322 message cannot be serialized without a sender, and a From: header missing or empty would produce an invalid/unsendable EML. Wrapped into a typed ValidationError by the mail command layer.

Source

Thrown at shortcuts/mail/emlbuilder/builder.go:679

		out = append(out, a.Address)
	}
	return out
}

// Build validates the builder and returns the raw EML bytes.
//
// Constraints (Lark API requirements):
//   - From is mandatory.
//   - At least one of To/CC/BCC must be set.
//   - Line endings are LF (\n), not CRLF.
//   - Content-Type parameters are written on a single line (no header folding).
//   - Non-ASCII body content is base64 (StdEncoding) encoded.
func (b Builder) Build() ([]byte, error) {
	if b.err != nil {
		return nil, b.err
	}
	if b.from.Address == "" {
		return nil, fmt.Errorf("emlbuilder: From address is required") //nolint:forbidigo // intermediate EML builder error; mail command layer wraps into typed ValidationError.
	}
	if !b.allowNoRecipients && len(b.to)+len(b.cc)+len(b.bcc) == 0 {
		return nil, fmt.Errorf("emlbuilder: at least one recipient (To/CC/BCC) is required") //nolint:forbidigo // intermediate EML builder error; mail command layer wraps into typed ValidationError.
	}

	date := b.date
	if date.IsZero() {
		date = time.Now()
	}

	msgID := b.messageID
	if msgID == "" {
		msgID = fmt.Sprintf("%d.%d@larksuite-cli", date.UnixNano(), rand.Int63())
	}

	var buf bytes.Buffer

	// ── Top-level headers ──────────────────────────────────────────────────────

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Call b.From("sender@example.com") (with optional display name) before Build().
  2. Check the config/env value feeding the sender address is non-empty before building.
  3. If building programmatically, assert from != "" in a pre-check and fail with a clearer application-level message.

Example fix

// before
b.To("a@x.com")
raw, err := b.Build() // error: From address is required
// after
b.From("me@example.com")
b.To("a@x.com")
raw, err := b.Build()
Defensive patterns

Strategy: validation

Validate before calling

if sender == "" {
    return errors.New("sender address is not configured; set it before building the EML")
}
b.From(sender)

Try / catch

raw, err := b.Build()
if err != nil {
    var verr *ValidationError
    if errors.As(err, &verr) && strings.Contains(err.Error(), "From address is required") {
        return fmt.Errorf("sender not configured: %w", verr)
    }
    return err
}

Prevention

When it happens

Trigger: Calling Build() without having called From() first, or calling From with an address-only argument whose address part is empty (e.g. From("" ) or From(" <>")).

Common situations: Code paths that set recipients but forget the sender; sender address resolved from config/env that is empty on a fresh install; conditional logic that skips From when a 'sender' field is blank.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04). Data as JSON: /api/errors/8444ee4c5ca7c73e. Report an issue: GitHub.