{"record":{"id":"8444ee4c5ca7c73e","repo":"larksuite/cli","slug":"emlbuilder-from-address-is-required","errorCode":null,"errorMessage":"emlbuilder: From address is required","messagePattern":"emlbuilder: From address is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/mail/emlbuilder/builder.go","lineNumber":679,"sourceCode":"\t\tout = append(out, a.Address)\n\t}\n\treturn out\n}\n\n// Build validates the builder and returns the raw EML bytes.\n//\n// Constraints (Lark API requirements):\n//   - From is mandatory.\n//   - At least one of To/CC/BCC must be set.\n//   - Line endings are LF (\\n), not CRLF.\n//   - Content-Type parameters are written on a single line (no header folding).\n//   - Non-ASCII body content is base64 (StdEncoding) encoded.\nfunc (b Builder) Build() ([]byte, error) {\n\tif b.err != nil {\n\t\treturn nil, b.err\n\t}\n\tif b.from.Address == \"\" {\n\t\treturn nil, fmt.Errorf(\"emlbuilder: From address is required\") //nolint:forbidigo // intermediate EML builder error; mail command layer wraps into typed ValidationError.\n\t}\n\tif !b.allowNoRecipients && len(b.to)+len(b.cc)+len(b.bcc) == 0 {\n\t\treturn 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.\n\t}\n\n\tdate := b.date\n\tif date.IsZero() {\n\t\tdate = time.Now()\n\t}\n\n\tmsgID := b.messageID\n\tif msgID == \"\" {\n\t\tmsgID = fmt.Sprintf(\"%d.%d@larksuite-cli\", date.UnixNano(), rand.Int63())\n\t}\n\n\tvar buf bytes.Buffer\n\n\t// ── Top-level headers ──────────────────────────────────────────────────────","sourceCodeStart":661,"sourceCodeEnd":697,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/mail/emlbuilder/builder.go#L661-L697","documentation":"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.","triggerScenarios":"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(\" <>\")).","commonSituations":"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.","solutions":["Call b.From(\"sender@example.com\") (with optional display name) before Build().","Check the config/env value feeding the sender address is non-empty before building.","If building programmatically, assert from != \"\" in a pre-check and fail with a clearer application-level message."],"exampleFix":"// before\nb.To(\"a@x.com\")\nraw, err := b.Build() // error: From address is required\n// after\nb.From(\"me@example.com\")\nb.To(\"a@x.com\")\nraw, err := b.Build()","handlingStrategy":"validation","validationCode":"if sender == \"\" {\n    return errors.New(\"sender address is not configured; set it before building the EML\")\n}\nb.From(sender)","typeGuard":null,"tryCatchPattern":"raw, err := b.Build()\nif err != nil {\n    var verr *ValidationError\n    if errors.As(err, &verr) && strings.Contains(err.Error(), \"From address is required\") {\n        return fmt.Errorf(\"sender not configured: %w\", verr)\n    }\n    return err\n}","preventionTips":["Always call From() immediately after constructing the Builder.","Fail fast at config load time when the sender address is empty.","Add a smoke test building a canonical message to catch missing-sender regressions."],"tags":["email","required-field","eml","validation"],"backgroundTag":"missing-required-argument","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}