Skip to main content
The BosonMail SDK automatically chooses between JSON and multipart encoding, normalizes inputs, and maps API responses into typed results. This page documents those rules so you can debug requests, build direct API calls, or write wrappers.

JSON requests (no attachments)

When the email has no attachments, the SDK sends:

Serialization rules

Undefined fields are omitted by JSON.stringify, so the request body contains only populated values.

Example JSON body

Multipart requests (with attachments)

When one or more attachments are present, the SDK builds a FormData body and deliberately does not set Content-Type. The runtime sets the header automatically with the correct boundary.

Field mapping

Blob construction

The SDK wraps attachment content as follows:
  • Blob or File: passed as-is. The Blob’s own type is used; the SDK ignores contentType for Blob inputs.
  • Uint8Array or ArrayBuffer: wrapped in a Blob with type set to contentType if provided, otherwise "application/octet-stream".
  • Buffer (Node.js): accepted because it is a Uint8Array subclass.
Attachments are never Base64-encoded inside JSON.

Response parsing

The SDK parses every response body as JSON. If parsing fails or the body is not an object, the SDK treats it as {}.

Success detection

A response is considered successful only when all of the following are true:
  1. response.ok is true (HTTP 200-299).
  2. The parsed body is an object.
  3. body.success === true.
If any condition fails, the SDK returns a failure result.

sendEmail result mapping

On success, the SDK maps the API response to a Result object: On failure:

getEmailStatus result mapping

On success, the SDK maps the API response to an EmailStatusResult: On failure:

Timeouts

The SDK uses AbortController with setTimeout per request. The default timeout is 30,000 ms and is configurable via the timeoutMs constructor option. When a timeout occurs, the SDK resolves with:
No statusCode is included for timeouts or network errors.

Next steps

API reference

Endpoint paths, curl examples, and parameter details.

Error codes

Full catalog of error codes and how to resolve them.

Rate limits

Plan allowances and defensive sending practices.

Troubleshooting

Fix serialization and timeout issues.