Skip to main content
The BosonMail SDK is configured entirely through the constructor. There are no global settings, no config files, and no middleware. Create one client per API key and reuse it across your application.

Constructor options

string
required
Your BosonMail API key. The constructor throws if it is empty or whitespace-only.
string
The BosonMail API base URL. Defaults to https://webmail.bosonware.com/api/v1. The constructor strips trailing slashes and validates that the value is an absolute HTTP(S) URL.
number
Request timeout in milliseconds. Defaults to 30000 (30 seconds). The constructor throws if the value is not a finite number greater than zero.

Default configuration

lib/bosonmail.ts

Per-environment configuration

Use different keys or base URLs for development, staging, and production. Never commit production credentials.
lib/bosonmail.ts
.env.development
.env.production

Choosing a timeout

The default 30 seconds is suitable for most transactional email sends, including multipart uploads with attachments. Consider a shorter timeout for health checks or high-volume loops where you want fast failure feedback. Consider a longer timeout only if you routinely send large attachments over slow links.
If a request times out, the SDK returns success: false with the message Request timed out after <timeoutMs>ms. The outcome may be unknown; check email status before retrying. The server may have accepted the message even though the client did not receive the response.

Validating configuration at startup

Because the constructor throws for invalid input, initializing the client during application startup is a reliable way to fail fast on misconfiguration.
server.ts

Common configuration mistakes

The constructor throws Error("'apiKey' must be a non-empty string"). Guard the environment variable before constructing the client.
The constructor throws Error("'baseUrl' must be an absolute HTTP(S) URL") if the value does not start with http:// or https://. It also throws Error("'baseUrl' must be a non-empty URL") if the trimmed value is empty.
The constructor throws Error("'timeoutMs' must be a positive number") if the value is not a finite number greater than zero.

Next steps

Client reference

Detailed constructor behavior, properties, and option types.

Authentication

API keys, Bearer tokens, and security best practices.

Sending emails

How to send text and HTML messages with the configured client.

Error handling

Interpret failure results and decide when to retry.