{"record":{"id":"cf4efec9f19cb914","repo":"larksuite/cli","slug":"emlbuilder-eml-size-1f-mb-exceeds-the-0f-mb-l","errorCode":null,"errorMessage":"emlbuilder: EML size %.1f MB exceeds the %.0f MB limit","messagePattern":"emlbuilder: EML size %\\.1f MB exceeds the %\\.0f MB limit","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/mail/emlbuilder/builder.go","lineNumber":761,"sourceCode":"\t\touterB := newBoundary()\n\t\twriteHeader(&buf, \"Content-Type\", \"multipart/mixed; boundary=\"+outerB)\n\t\tbuf.WriteByte('\\n')\n\n\t\tfmt.Fprintf(&buf, \"--%s\\n\", outerB)\n\t\twritePrimaryBody(&buf, b)\n\n\t\tfor _, att := range b.attachments {\n\t\t\tfmt.Fprintf(&buf, \"--%s\\n\", outerB)\n\t\t\twriteAttachmentPart(&buf, att)\n\t\t}\n\t\tfmt.Fprintf(&buf, \"--%s--\\n\", outerB)\n\t} else {\n\t\twritePrimaryBody(&buf, b)\n\t}\n\n\traw := buf.Bytes()\n\tif len(raw) > MaxEMLSize {\n\t\treturn nil, fmt.Errorf(\"emlbuilder: EML size %.1f MB exceeds the %.0f MB limit\", //nolint:forbidigo // intermediate EML builder error; mail command layer wraps into typed ValidationError.\n\t\t\tfloat64(len(raw))/1024/1024, float64(MaxEMLSize)/1024/1024)\n\t}\n\treturn raw, nil\n}\n\n// BuildBase64URL returns the EML encoded as base64url (RFC 4648).\n// This is the value to place in the Lark API \"raw\" field.\nfunc (b Builder) BuildBase64URL() (string, error) {\n\traw, err := b.Build()\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\treturn base64.URLEncoding.EncodeToString(raw), nil\n}\n\n// ── internal helpers ──────────────────────────────────────────────────────────\n\n// copySlices returns a shallow copy of b with independent slice headers,","sourceCodeStart":743,"sourceCodeEnd":779,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/mail/emlbuilder/builder.go#L743-L779","documentation":"Build() enforces MaxEMLSize; when the fully serialized EML exceeds the limit it returns this error instead of producing an oversized message that the mail API would reject. The error reports both the actual size in MB and the configured limit in MB. Wrapped into a typed ValidationError by the mail command layer.","triggerScenarios":"Calling Build() after attaching many/large files or very large bodies such that the serialized raw EML byte length exceeds MaxEMLSize (reported as MB in the message).","commonSituations":"Attaching several large attachments (videos, datasets, high-res images) to one email; inlining many base64-encoded images; base64 expansion (~+33%) pushing a just-under-limit payload over the cap.","solutions":["Reduce the number or size of attachments; remove non-essential ones.","Upload large files via Drive/cloud links instead of embedding them as attachments.","Compress or resize attachments (e.g. images to jpeg/webp, zip archives where allowed) before adding them.","Check the estimated size in the application (sum of base64-encoded parts) before Build() and split into multiple messages."],"exampleFix":"// before\nb.AddFileAttachment(\"video-raw-4k.mp4\") // 60 MB -> serialized EML exceeds limit\n// after\nlink := uploadToDrive(\"video-raw-4k.mp4\")\nb.AddFileAttachment(\"link.txt\") // or share the Drive link in the body","handlingStrategy":"validation","validationCode":"const maxEML = 25 << 20 // match MaxEMLSize\nvar total int\nfor _, a := range attachments {\n    total += len(a.data) + len(a.data)/2 + 1024 // approximate base64 expansion\n}\nif total > maxEML {\n    return fmt.Errorf(\"attachments (%d MB) would exceed the EML limit; use Drive links\", total>>20)\n}","typeGuard":null,"tryCatchPattern":"raw, err := b.Build()\nif err != nil {\n    var verr *ValidationError\n    if errors.As(err, &verr) && strings.Contains(err.Error(), \"exceeds the\") {\n        return fmt.Errorf(\"message too large: %w\", verr)\n    }\n    return err\n}","preventionTips":["Estimate serialized size (base64 adds ~33%) before attaching large files.","Use cloud/Drive links for files above a few MB instead of attachments.","Compress images and documents before attaching.","Split very large payloads across multiple messages."],"tags":["email","size-limit","attachments","eml"],"backgroundTag":"payload-too-large","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"}