BosonMailClient. All settings are passed through the BosonMailClientOptions object. The constructor validates every option immediately and throws descriptive errors for invalid input.
BosonMailClientOptions
string
required
Your BosonMail API key. Must be a non-empty string after trimming. Keep this in an environment variable or secrets manager, never in source control.
string
The API base URL. Defaults to
https://webmail.bosonware.com/api/v1. Must be an absolute URL starting with http:// or https://.number
Per-request timeout in milliseconds. Defaults to
30000 (30 seconds). Must be a finite number greater than 0.Defaults and normalization
The normalized
baseUrl is stored on client.apiBaseUrl. The original apiKey is stored on client.apiKey (trimmed but otherwise unchanged).
Constructor errors
The constructor throwsError with the following exact messages:
These are the only errors the SDK throws. Every other failure is returned as a result object.
Examples
Default configuration
lib/bosonmail.ts
Custom timeout
Use a shorter timeout for latency-sensitive paths, or a longer one when sending large attachments:Custom base URL
Point to a staging environment or a self-hosted BosonMail instance:Timeout behavior
Every request uses anAbortController with a setTimeout equal to timeoutMs. If the timer fires before the response arrives, the request is aborted and the method resolves with:
BosonMailClient
Class overview, methods, and exported types.
Sending emails
Full sendEmail reference with parameters and examples.
Error handling
How to classify and respond to every kind of SDK error.
Authentication
How to obtain and store your API key.