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
Constructor
Constructor behavior
apiKey(required): trimmed and stored asclient.apiKey.baseUrl(optional): defaults tohttps://webmail.bosonware.com/api/v1. Trimmed, trailing slashes stripped, and stored asclient.apiBaseUrl.timeoutMs(optional): defaults to30000. Must be a finite number greater than0.
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
Recommended pattern: one shared instance
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.