Quick setup examples

Nuxt

Send your first email from a Nuxt server route using the sendping SDK.

Send your first email from a Nuxt app using the sendping Node SDK. Install it with npm install sendping, then import SendPing and call mb.emails.send(). A Nuxt server route keeps the key on the server, where it belongs.

Prerequisites

1. Install the SDK

npm install sendping

2. Add your API key

Store your key in .env. Nuxt reads it server-side from process.env.

.env
SENDPING_API_KEY=mb_xxxxxxxxx

3. Send email from a server route

Create a server route under server/api/send.ts. Instantiate the SDK client with the key from process.env and call mb.emails.send().

server/api/send.ts
import { SendPing } from 'sendping';

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

export default defineEventHandler(async () => {
  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>',
  });

  if (error) {
    throw createError({ statusCode: 500, message: 'Error sending email' });
  }

  return data;
});
A successful call returns the created email's id. See the full request body in the Send an email reference.