Quick setup examples

Express

Send your first email from an Express route using the mailblastr SDK.

Send your first email from an Express server using the mailblastr Node SDK. Install it with npm install mailblastr, then import MailBlastr and call mb.emails.send() inside your route handler.

Prerequisites

1. Install the SDK

npm install mailblastr

2. Add your API key

.env
MAILBLASTR_API_KEY=mb_xxxxxxxxx

3. 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 { MailBlastr } from 'mailblastr';

const app = express();
const mb = new MailBlastr(process.env.MAILBLASTR_API_KEY);

app.get('/', async (req: Request, res: Response) => {
  const { data, error } = await mb.emails.send({
    from: 'Acme <onboarding@yourdomain.com>',
    to: ['delivered@example.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.