Key management and rotation
Your API key grants access to your BosonMail account. Protect it as you would any production secret.Store the key in an environment variable or a secrets manager. Never commit it to version control.
Load the key at runtime and fail fast if it is missing.
Do not expose the key in browser code, frontend bundles, or client-side logs.
lib/bosonmail.ts
Not yet documented by BosonWare: how to create, rotate, or revoke API keys, and the full list of available scopes. Contact support@bosonware.com for guidance.
Single client instance
InstantiateBosonMailClient once and reuse it across your application. The client is stateless and safe to share between requests.
Timeouts
The SDK defaults to 30 seconds. TunetimeoutMs to match your infrastructure and user expectations.
Never-throwing assumption
The SDK constructor is the only place it throws. Methods always resolve, even on validation, network, or timeout failures. Always checkresult.success before using result.id or result.messageId.
Logging without secrets or PII
Redact sensitive fields from logs. Do not log the client object, raw email content, or recipient lists at info level.Persist message IDs
Storeresult.messageId in your database so you can check status later. The SDK does not poll automatically, and a timeout gives you no message ID to query.
Status reconciliation
PollgetEmailStatus periodically for messages that have not reached a terminal state. The README treats delivered, failed, bounced, and rejected as terminal. Do not treat deferred or sent as terminal.
Retry policy
The SDK does not retry automatically. Implement retries in your application only for transient failures.When to retry
When to retry
Retry only when there is no
statusCode due to a non-timeout network error, or when statusCode is 500 or greater, or 429. Do not retry 4xx validation errors.When not to retry
When not to retry
Do not blindly retry after a timeout. The SDK returns no
messageId on timeout, so you cannot look up the status. Log the failure and reconcile manually, or accept a duplicate risk explicitly.Queueing sends
For user-facing latency, do not block the HTTP response while waiting for BosonMail. Push send jobs to a background queue and return immediately.Protect your send endpoints
An unprotected send endpoint is an open relay. Secure it before going live.Require authentication on every send request.
Add rate limiting per user or IP.
For public contact forms, use a CAPTCHA and a strict recipient allowlist.
Validate and sanitize all inputs before passing them to the SDK.
HTML escaping
If you render user-generated content into HTML email bodies, escape it to prevent injection. Use a trusted library or framework auto-escaping.Attachment validation
The SDK validates attachment size and count, but you should also validate files in your own middleware:- Reject unexpected file types at the application layer.
- Enforce per-file and total size limits before the SDK sees the data.
- Scan uploads for malware if your use case requires it.
Monitor outbound allowance
Each BosonMail inbox includes 500 outbound emails per month. Emails sent through the SDK likely count against this allowance, but confirm this with BosonWare. Track your volume and set alerts before you approach the limit.BosonWare has not confirmed whether SDK/API sends count against the 500 outbound emails per inbox per month. Contact support@bosonware.com to verify.
Pin SDK versions
The BosonMail SDK is pre-1.0. Minor version bumps may change behavior. For example, 0.2.1 changed JSON request serialization forto, cc, and bcc. Pin the exact version in package.json and review the changelog before upgrading.
package.json
Testing with dependency injection
Make the client injectable so tests can substitute a stub without touching the network.sendEmail on a real client configured with a test baseUrl.
Related
Error handling
SDK error codes, validation failures, and timeout behavior.
Email status
How to check delivery status with getEmailStatus.
Security
Security considerations for API keys and data handling.
Rate limits
What is known and unknown about API rate limiting.