# SendCorrespondenceEmail - Advanced Documentation ## Model Shape (CorrespondenceInfo) ``` Type: "Email" | "Text" -- CorrespondenceInfo.CorrespondenceType Subject: string Body: string -- required message content ShortMessage: string -- DERIVED, do not set (GetPreviewText(Body)) From: CorrespondenceParticipantInfo -- required; overwritten server-side (see traps) Tos / CCs / Bccs: CorrespondenceParticipantInfo[] Claims: {Key:ClaimID, Value:FirmID}[] Contacts: {Key:ContactID, Value:FirmID}[] ExternalID: string -- required when Action is Reply or Forward CorrespondenceParticipantInfo: Name: string Value: string -- email address; drives recipient delivery Display: string -- optional, defaults to Value ``` ## Traps - `Action` is `Controllers.Correspondence.CorrespondenceAction`: `Create`, `Reply`, `Forward`. `Reply`/`Forward` throw `"An ExternalID must be provided in a reply or forward."` if `Correspondence.ExternalID` is blank. - At least one Claim or Contact is required. Missing both throws `"At least one Claim or Contact is required to send Related Correspondence."` - Only Claims/Contacts whose FirmID matches the current company are used; others are silently dropped before the check above runs. - `From` is fully replaced with the authenticated user's identity (Name, Value, Display all overwritten). Whatever `From` you send is discarded. - `ShortMessage` is derived from `Body` via `GetPreviewText`; do not set it, it is not read from the caller. - Recipient delivery is driven by `Value` (must be a real email address); `ContactItemType` has no effect on routing. - Do not confuse `CorrespondenceInfo.Type` ("Email"/"Text") with the unrelated `CorrespondenceType` string parameter on `GetCorrespondencePossibleParticipants` ("Claim"/"Contact") - same name, different concept. - `CCs` and `Bccs` must be arrays, never null. Send `[]` when empty. - The server appends no signature. Compose `Body` as optional snippet content plus at most one signature: the user's own signature for that message type (`GetEmailSignaturesResolved`), else the firm default snippet for that type (`MergeHTMLSnippet`), else none. Never stack a personal signature and the firm default. - Attachments: upload the file with `FileService.GetUploadUrl` first. On the attachment, set `StorageName` to the name that upload returns and set `DownloadUrl` to that same name prefixed with `s3:` (for example `"s3:" + StorageName`). An https URL in `DownloadUrl` is not accepted. ## Script Example This is a long-running operation - never await it directly, awaiting kills the script. Fire it without awaiting, return your own ProcessID, then poll for the result in separate later script calls. ```javascript async () => { const correspondence = { Subject: "Case update", Body: "
Your claim has been updated.
", Tos: [{ Value: "client@example.com", Name: "Jane Client" }], Claims: [{ Key: 12345, Value: 625 }] }; const processId = crypto.randomUUID(); SecureApi.SendCorrespondenceEmail(processId, "Create", correspondence); // not awaited - long-running return { processId }; } ``` In a separate later script call, poll `GetProcessStatus(processId)` until it returns exactly `processId + ":complete"` or `processId + ":error"` - every other value, including an empty string, means still running. Once terminal, call `GetProcessResult(processId)` exactly once to get the result or error; calling it before a terminal status clears the status permanently. ## Cross-References | Need | Use Instead | |------|-------------| | Email without claim/contact (not persisted) | `SendEmail(ProcessID, Correspondence)` | | SMS tied to a claim/contact (persisted) | `SendCorrespondenceSms(ProcessID, Action, Correspondence)` |