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

  1. Compute the file's byte length and lowercase hexadecimal SHA-256 hash.
  2. Call POST /v1/attachments with filename, contentType, bytes, and contentHash. Save the returned attachment ID.
  3. PUT the exact file bytes to the returned uploadUrl, using every header in requiredHeaders. Upload before expiresAt, and keep the upload URL private.
  4. Call POST /v1/attachments/:id/complete. Completion queues the attachment check. It does not mean the file is ready.
  5. Poll GET /v1/attachments/:id with bounded backoff until state is clean. While state is scanning, the check is still running. If it is rejected or expired, inspect the reason and correct the problem before you upload again.
  6. Include the clean IDs in the email request's attachmentIds array.

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

LimitValue
Combined raw attachments per message15,000,000 bytes (15 MB)
Complete encoded MIME message40,000,000 bytes (40 MB)
Attachments per email20

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.