Quick setup examples
Express
Send your first email from an Express route using the senddart SDK.
Send your first email from an Express server using the senddart Node SDK. Install it with npm install senddart, then import SendDart and call mb.emails.send() inside your route handler.
Prerequisites
- A SendDart API key.
- A verified domain to send from.
- Node.js 18 or newer.
1. Install the SDK
npm install senddart2. Add your API key
.env
SENDDART_API_KEY=mb_xxxxxxxxx3. Send email from a route
Instantiate the SDK client once at module scope and call mb.emails.send() inside your handler.
server.ts
import express, { Request, Response } from 'express';
import { SendDart } from 'senddart';
const app = express();
const mb = new SendDart(process.env.SENDDART_API_KEY!);
app.get('/', async (req: Request, res: Response) => {
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>',
});
res.status(error ? 400 : 200).json(error ? { error } : { data });
});
app.listen(3000, () => {
console.log('Listening on http://localhost:3000');
});A successful call returns the created email's
id. See the full request body in the Send an email reference.