sendsend.email

Send email with Astro

A server-side call to the SendSend API from your Astro 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 read it from import.meta.env (server-side endpoints only).
  3. Add this to src/pages/api/send.ts:
import type { APIRoute } from 'astro';

export const POST: APIRoute = async ({ request }) => {
  const { to } = await request.json();
  const res = await fetch('https://api.sendsend.email/v1/emails', {
    method: 'POST',
    headers: { Authorization: `Bearer ${import.meta.env.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 Astro', html: '<p>It works!</p>' }),
  });
  return new Response(await res.text(), { status: res.status, headers: { 'Content-Type': 'application/json' } });
};

This needs Astro’s server output (an adapter), because the endpoint runs on the server.

Good to know