Quick setup examples

Express

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

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

Prerequisites

1. Install the SDK

npm install sendping

2. Add your API key

.env
SENDPING_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 { SendPing } from 'sendping';

const app = express();
const mb = new SendPing(process.env.SENDPING_API_KEY!);

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