Astro

Send email from Astro endpoints and server routes.

Send email from Astro endpoints and server routes.

Install

npm i resent.one

Set RESENT_API_KEY in your server environment. Keep the key off the client.

Send an email

// src/pages/api/send.ts
import type { APIRoute } from "astro";
import { Resent } from "resent.one";
export const POST: APIRoute = async () => {
const resent = new Resent(import.meta.env.RESENT_API_KEY);
const result = await resent.emails.send({
from: "Acme <noreply@yourdomain.com>",
to: "you@example.com",
subject: "Hello from Astro",
html: "<strong>It works!</strong>",
});
return new Response(JSON.stringify(result), {
headers: { "Content-Type": "application/json" },
});
};

Next steps