Send email with Nuxt
A server-side call to the SendSend API from your Nuxt app.
- Create a test API key in the dashboard first: it never delivers real email. Switch to a live key once your domain is verified.
- Set NUXT_SENDSEND_API_KEY in .env and read it with useRuntimeConfig(event).sendsendApiKey (declare it under runtimeConfig in nuxt.config.ts, private, not public).
- Add this to
server/api/send.post.ts:
export default defineEventHandler(async (event) => {
const { to } = await readBody(event);
const { sendsendApiKey } = useRuntimeConfig(event);
return await $fetch('https://api.sendsend.email/v1/emails', {
method: 'POST',
headers: { Authorization: `Bearer ${sendsendApiKey}`, 'Idempotency-Key': crypto.randomUUID() },
body: { from: 'Acme <hello@mail.acme.com>', to: [to], subject: 'Hello from Nuxt', html: '<p>It works!</p>' },
});
});Good to know
- A
202response means the message was queued, not delivered. See message states and webhooks. - Always send an Idempotency-Key, so a retry cannot send twice.
- Check the response status. Errors have one shape: see Errors.
- More options: attachments, scheduling, headers, templates and React Email.