Prerequisites
You need Node.js 18 or newer because the SDK uses nativefetch, FormData, Blob, and AbortController. You also need a BosonMail API key with email sending permission. If you do not have one yet, sign up at BosonMail and contact support@bosonware.com for API key provisioning steps.
1
Initialize the project
Create a new folder and initialize it as an ESM Node.js project.Open
package.json and add "type": "module" so Node.js treats .js and .ts files as ESM:package.json
2
Install the SDK and dev tools
Install the BosonMail SDK, TypeScript, and Generate a basic
tsx for running TypeScript without compiling.tsconfig.json:3
Configure environment variables
Create a Create a
.env file to store your API key outside source control..env
.gitignore file so the key is never committed..gitignore
4
Write the sender script
Create
src/send.ts with a shared client, full error handling, and a status check.src/send.ts
5
Run the script
Load the environment variable and execute the sender.If you do not have
dotenv-cli installed, you can run:Interpreting the output
WhensendEmail succeeds, the SDK returns an object like this:
success: truemeans the API accepted the message. It does not mean the recipient has received it yet.statusis typically"queued"immediately after submission.messageIdis the identifier you pass togetEmailStatusto poll for delivery progress.
success is false and you get errorMessage plus statusCode when the server responded:
Common first-run problems
BOSONMAIL_API_KEY is not set
BOSONMAIL_API_KEY is not set
Make sure the environment variable is loaded before the script runs. Using
dotenv-cli or exporting the variable directly both work. On Windows PowerShell, use $env:BOSONMAIL_API_KEY = "your_api_key".'to' must contain at least one recipient
'to' must contain at least one recipient
The
to argument must be a non-empty string or a non-empty array of strings. Double-check for accidental empty strings or arrays.Request timed out after 30000ms
Request timed out after 30000ms
The default timeout is 30 seconds. A timeout leaves the outcome uncertain: the server may have accepted the message even though the client did not receive the response. Check the email status with the message ID if you have it, or reconcile before retrying to avoid duplicates.
Next steps
Sending HTML emails
Build rich order confirmations and marketing emails with inline styles and plain-text fallbacks.
Sending with attachments
Attach PDF invoices, CSV exports, and other files to your emails.
Multiple recipients
Send to many recipients using To, CC, BCC, or individual personalized emails.
Monitoring delivery
Poll for delivery status and build a reconciliation workflow around message IDs.