1
Get an API key
You need a BosonMail API key to send email. Log in to your BosonMail account and generate a key with permission to send email.
2
Install the SDK
Install the package with npm, Bun, pnpm, or Yarn. The SDK is ESM-only and requires Node.js 18+.See Installation for TypeScript setup and CommonJS workarounds.
npm
3
Set your environment variable
Create a For Node.js 20.6 and newer, load it automatically when you run your script:Bun loads
.env file in your project root and add your API key..env
.env automatically by default.4
Write and run the send script
Create a file that sends a plain-text email and prints the result.Run it:
TypeScript
JavaScript (Node 20.6+)
Bun
5
Check the email status
If The
result.success is true and result.messageId is present, you can look up the delivery state.status.ts
status field is the current email state reported by BosonMail. The delivery_status reflects the delivery outcome from the receiving server. Values include queued, sent, delivered, failed, bounced, rejected, and deferred. The exact meaning and transition order depend on the BosonMail backend implementation.What the result means
A successfulsendEmail response means BosonMail accepted the message for processing. The typical status is "queued". It does not guarantee delivery. Persist messageId in your database so you can audit or retry later.
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. Do not blindly retry after a timeout. Log the attempt and reconcile manually, or accept a small duplicate risk if you choose to resend.Next steps
Sending emails
Learn about recipients, CC, BCC, HTML content, and result handling.
Email status
Poll for delivery, interpret statuses, and build audit trails.
Attachments
Add files to your messages with size limits and content types.
Next.js guide
Integrate BosonMail into API routes and server actions.