uSend Docs
Quickstarts

Send with Nuxt

Send email from a Nuxt server route with the usend SDK.

You need a verified domain and an API key. Nitro server routes run on the server only.

1. Install

Shell
npm install @usend/node

2. Configure the key

nuxt.config.ts
export default defineNuxtConfig({
  runtimeConfig: {
    usendApiKey: '', // private: set NUXT_USEND_API_KEY in the environment
  },
});
.env
NUXT_USEND_API_KEY=us_123456789

Keys under runtimeConfig but outside public are never sent to the browser.

3. Server route

server/api/send.post.ts
import { Usend } from '@usend/node';

export default defineEventHandler(async (event) => {
  const { usendApiKey } = useRuntimeConfig(event);
  const usend = new Usend(usendApiKey);
  const { email } = await readBody(event);

  const { data, error } = await usend.emails.send({
    from: 'Acme <[email protected]>',
    to: [email],
    subject: 'Welcome to Acme',
    html: '<p>Thanks for signing up.</p>',
  });

  if (error) {
    throw createError({ statusCode: error.statusCode || 500, statusMessage: error.message });
  }
  return { id: data.id };
});

4. Call it from a page

pages/index.vue
<script setup lang="ts">
const email = ref('');
async function send() {
  await $fetch('/api/send', { method: 'POST', body: { email: email.value } });
}
</script>

<template>
  <form @submit.prevent="send">
    <input v-model="email" type="email" required />
    <button>Send welcome email</button>
  </form>
</template>

Your page talks to your own route; the route talks to usend. Next: Send emails.