Bun.file, and write tests with mocked clients.
BosonWare builds the BosonMail package with Bun (
prepublishOnly: bun run build) and documents bun add in the README. Bun loads .env files automatically, so no extra dotenv package is required.Prerequisites
- Bun 1.0 or later
- A BosonMail API key
Project setup
1
Initialize the project
Create a new Bun project with TypeScript support.
2
Install the SDK
Add the BosonMail SDK from the npm registry.
3
Add environment variables
Create a
.env file in the project root. Bun loads it automatically on startup..env
Sending email from a script
Create a standalone script that reads the API key fromBun.env or process.env and sends a simple email.
send.ts
Sending attachments with Bun.file
Read files directly intoArrayBuffer and pass them to the SDK.
send-with-attachment.ts
Bun.file returns a BunFile that implements Blob. Calling .arrayBuffer() gives you an ArrayBuffer, which the SDK accepts directly. You can also pass the BunFile itself as the content because it is a Blob subclass.HTTP server with Bun.serve
Expose a minimal HTTP endpoint that accepts JSON and sends email.server.ts
Testing with Bun test
Bun has a built-in test runner. Mock the client by injecting a stub or by replacing the module import.send.test.ts
Related
Sending emails
SDK reference for sendEmail and its options.
Email status
How to check delivery status with getEmailStatus.
Production best practices
Key management, retries, logging, and monitoring guidance.
Attachments
SDK reference for sending file attachments.