Skip to main content
This guide walks you through creating a fresh Node.js project from an empty folder, installing the BosonMail SDK, and sending your first email. You will write a complete script with error handling, check the submission status, and learn how to interpret the response.

Prerequisites

You need Node.js 18 or newer because the SDK uses native fetch, 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 tsx for running TypeScript without compiling.
Generate a basic tsconfig.json:
3

Configure environment variables

Create a .env file to store your API key outside source control.
.env
Create a .gitignore file so the key is never committed.
.gitignore
Never commit API keys to version control. Treat .env as sensitive and share keys only through a secrets manager.
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

When sendEmail succeeds, the SDK returns an object like this:
  • success: true means the API accepted the message. It does not mean the recipient has received it yet.
  • status is typically "queued" immediately after submission.
  • messageId is the identifier you pass to getEmailStatus to poll for delivery progress.
If the call fails, success is false and you get errorMessage plus statusCode when the server responded:

Common first-run problems

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".
The to argument must be a non-empty string or a non-empty array of strings. Double-check for accidental empty strings or arrays.
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.
Verify that your key is active and has the required scope. The exact scopes are not yet documented by BosonWare: contact support@bosonware.com if you are unsure.

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.