Quick setup examples
Bun
Send your first email from a Bun server using the senddart SDK.
Send your first email from a Bun app using the senddart SDK. Bun reads .env automatically and is fully compatible with the Node SDK. Install it with bun add senddart, then import SendDart and call mb.emails.send().
Prerequisites
- A SendDart API key.
- A verified domain to send from.
1. Install the SDK
bun add senddart2. Add your API key
Bun loads .env automatically and exposes it on process.env / Bun.env.
.env
SENDDART_API_KEY=mb_xxxxxxxxx3. Send email from a Bun server
Create index.ts, instantiate the SDK client, and call mb.emails.send() from the request handler. Start it with bun index.ts.
index.ts
import { SendDart } from 'senddart';
const mb = new SendDart(Bun.env.SENDDART_API_KEY);
const server = Bun.serve({
port: 3000,
async fetch() {
const { data, error } = await mb.emails.send({
from: 'Acme <onboarding@yourdomain.com>',
to: ['delivered@test.senddart.com'],
subject: 'Hello World',
html: '<strong>It works!</strong>',
});
return Response.json(error ? { error } : { data }, {
status: error ? 500 : 200,
});
},
});
console.log(`Listening on http://localhost:${server.port} ...`);A successful call returns the created email's
id. See the full request body in the Send an email reference.