sendsend.email

Send email with SvelteKit

A server-side call to the SendSend API from your SvelteKit app.

  1. Create a test API key in the dashboard first: it never delivers real email. Switch to a live key once your domain is verified.
  2. Add SENDSEND_API_KEY to .env and import it from $env/static/private (server-only).
  3. Add this to src/routes/api/send/+server.ts:
import { json } from '@sveltejs/kit';
import { SENDSEND_API_KEY } from '$env/static/private';

export async function POST({ request }) {
  const { to } = await request.json();
  const res = await fetch('https://api.sendsend.email/v1/emails', {
    method: 'POST',
    headers: { Authorization: `Bearer ${SENDSEND_API_KEY}`, 'Content-Type': 'application/json', 'Idempotency-Key': crypto.randomUUID() },
    body: JSON.stringify({ from: 'Acme <hello@mail.acme.com>', to: [to], subject: 'Hello from SvelteKit', html: '<p>It works!</p>' }),
  });
  return json(await res.json(), { status: res.status });
}

Good to know