How to send emails with Nuxt

Nuxt (Nitro) runs server routes in `server/api`. Put the Publiq call in a server route and call it from your app.

Install the SDK (npm install publiq) and set PUBLIQ_API_KEY in your server environment. The code below runs on the server — the API key never reaches the client.

import { Publiq } from 'publiq';

const publiq = new Publiq(process.env.PUBLIQ_API_KEY);

export default defineEventHandler(async (event) => {
  const { to } = await readBody(event);
  const email = await publiq.emails.send({
    from: 'you@yourdomain.com',
    to,
    templateKey: 'welcome-email',
    variables: { first_name: 'Ana' },
  });
  return { id: email.id };
});

Best practices

  • Always call Publiq from the server — never expose the API key on the client.
  • Create the client instance once and reuse it across requests.
  • Prefer templateKey over inline HTML to keep content versioned.
  • Handle PubliqError (status/code); the SDK already retries transient errors with backoff.
  • Send from a verified domain — see Domains.

See also

How to send emails with Nuxt — Publiq Docs