Skip to main content
BosonMailClient is the single entry point of the BosonMail SDK. It holds your API key and base URL, and exposes two methods: sendEmail and getEmailStatus. The client is lightweight, has zero runtime dependencies, and is safe to instantiate once and reuse across your application.

Import

The package is ESM-only. Import the default export and any type you need.
lib/bosonmail.ts
For CommonJS, use a dynamic import:

Constructor

The constructor validates its arguments immediately and throws if anything is invalid. All other errors in the SDK are returned as result objects, never thrown.

Constructor behavior

  • apiKey (required): trimmed and stored as client.apiKey.
  • baseUrl (optional): defaults to https://webmail.bosonware.com/api/v1. Trimmed, trailing slashes stripped, and stored as client.apiBaseUrl.
  • timeoutMs (optional): defaults to 30000. Must be a finite number greater than 0.

Constructor errors (thrown)

Readonly properties

After construction, these properties are readable but not writable:
string
required
The API key passed to the constructor. Do not log the client object: it contains this secret.
string
required
The normalized base URL used for every request. Trailing slashes are removed.
number
required
Per-request timeout in milliseconds. Implemented with AbortController.

Methods

Both methods always resolve, even on network failure, timeout, or API error. They never throw.

Exported types

Create a single client in a module and import it wherever you need to send email or check status. This avoids repeating configuration and keeps the API key in one place.
lib/bosonmail.ts
The constructor is the only place the SDK throws. Methods return result objects so you can handle failures without try/catch around every call.

Client configuration

All options, defaults, validation rules, and timeout behavior.

Sending emails

Full reference for sendEmail, parameters, validation, and examples.

Email status

How to check delivery status with getEmailStatus.

Error handling

How to read and act on every kind of SDK error.