Skip to content
DocumentationAPI referenceBuild something worth sending.

Guides

Send email with Nuxt

Send email from a Nuxt server route with the SendPanda SDK. Do not expose the API key with a public runtime config.

Send from a Nuxt server route. defineEventHandler and readBody are Nuxt auto-imports. Put the key in the server environment, not in runtimeConfig.public.

1. Install

npm install @sendpanda/sdk

Create a Send emails key and store it as SENDPANDA_API_KEY. The from address has to be on a domain verified in that project. See domain setup. A queued status means the API accepted the email, not that the recipient's server delivered it.

2. Send from a server route

// server/api/welcome.post.ts
import { SendPanda } from "@sendpanda/sdk";

const panda = new SendPanda(process.env.SENDPANDA_API_KEY!);

export default defineEventHandler(async (event) => {
  const user = await requireUser(event); // your own session check
  const email = await panda.emails.send(
    {
      from: "Your app <hello@your-verified-domain.com>",
      to: [user.email],
      subject: "Welcome",
      text: "Welcome",
    },
    { idempotencyKey: `welcome-${user.id}` },
  );
  return { id: email.id, status: email.status };
});

requireUser is your code. The route must not send to an address taken from the request body.

A route that sends to any address a request supplies is an open relay. Decide the recipient from your own session or database. Use one idempotency key per business event, and reuse that same key if the request is retried.

↑↓ to navigate↵ to openesc to close