Sending
Attachments
Upload and check attachments for Ternwire emails, with raw and encoded size limits and usage billing explained.
On this page
Ternwire attachments use an upload-and-check flow. Upload the file bytes, complete the upload, and wait until the attachment is clean before you include its ID in an email request. A pending, rejected, expired, or foreign attachment cannot be sent.
Upload and wait for the attachment check
- Compute the file's byte length and lowercase hexadecimal SHA-256 hash.
- Call
POST /v1/attachmentswithfilename,contentType,bytes, andcontentHash. Save the returned attachment ID. - PUT the exact file bytes to the returned
uploadUrl, using every header inrequiredHeaders. Upload beforeexpiresAt, and keep the upload URL private. - Call
POST /v1/attachments/:id/complete. Completion queues the attachment check. It does not mean the file is ready. - Poll
GET /v1/attachments/:idwith bounded backoff untilstateisclean. Whilestateisscanning, the check is still running. If it is rejected or expired, inspect the reason and correct the problem before you upload again. - Include the clean IDs in the email request's
attachmentIdsarray.
The completion step verifies the stored bytes against the declared size and hash, so do not transform the file after computing these values. The check rejects executables, password-protected archives, and any contentType other than PDF, Word, Excel, PowerPoint, RTF, CSV, plain text, JSON, iCalendar, ZIP, PNG, JPEG, GIF, or WebP. Handle a rejection as an error rather than silently omitting an expected attachment.
Raw and encoded size limits
| Limit | Value |
|---|---|
| Combined raw attachments per message | 15,000,000 bytes (15 MB) |
| Complete encoded MIME message | 40,000,000 bytes (40 MB) |
| Attachments per email | 20 |
Base64 encoding and MIME headers increase the size of a message. A raw file's size alone does not tell you its encoded size, and the text and HTML bodies also count toward the full message limit. Oversized requests are rejected rather than split into multiple emails.
Usage is measured per accepted recipient
Attachment usage uses encoded attachment bytes, including MIME overhead, multiplied by accepted recipients. The message size limit and the attachment usage meter measure different things. The limit covers the whole message, while the meter covers its encoded attachments.
For example, 2 MB of encoded attachments sent to three accepted recipients consumes 6 MB of attachment allowance. See plan allowances and overage rates before you send large attachments to many recipients.