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

1// src/pages/api/send.ts
2import type { APIRoute } from "astro";
3import { Resent } from "resent.one";
4
5export const POST: APIRoute = async () => {
6 const resent = new Resent(import.meta.env.RESENT_API_KEY);
7 const result = await resent.emails.send({
8 from: "Acme <noreply@yourdomain.com>",
9 to: "you@example.com",
10 subject: "Hello from Astro",
11 html: "<strong>It works!</strong>",
12 });
13 return new Response(JSON.stringify(result), {
14 headers: { "Content-Type": "application/json" },
15 });
16};

Next steps