All guides

Send Email from Astro

Send emails from Astro API routes and server endpoints

1. Install the SDK

npm install sendpigeon

2. Set your API key

Add your SendPigeon API key to your environment variables:

SENDPIGEON_API_KEY=your_api_key_here

Get your API key from the dashboard.

3. Send your first email

// src/pages/api/contact.ts
import type { APIRoute } from "astro";
import { SendPigeon } from "sendpigeon";

const client = new SendPigeon(import.meta.env.SENDPIGEON_API_KEY);

export const POST: APIRoute = async ({ request }) => {
  const { email, name } = await request.json();

  await client.emails.send({
    from: "hello@yourdomain.com",
    to: email,
    subject: `Thanks for reaching out, ${name}!`,
    html: `<h1>We got your message</h1><p>We'll get back to you soon.</p>`,
  });

  return new Response(JSON.stringify({ success: true }), {
    status: 200,
    headers: { "Content-Type": "application/json" },
  });
};

Features

  • Works with Astro SSR mode
  • API routes and server endpoints
  • Deploy anywhere Astro runs

Ready to send emails?

Get started with 1,000 free emails per month.

Start for free