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
Empty or missing apiKey
Empty or missing apiKey
The constructor throws
Error("'apiKey' must be a non-empty string"). Guard the environment variable before constructing the client.Invalid baseUrl
Invalid baseUrl
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.Invalid timeoutMs
Invalid timeoutMs
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.