Learn how to send your first email using Astro and the Resend Node.js SDK.
To get the most out of this guide, you’ll need to:
Get the Resend Node.js SDK.
TODO: package manager tabs
Create and Endpoint under src/pages/api/send.ts
.
The easiest way to send an email is by using the html
parameter.
import type { APIRoute } from "astro";
import { Resend } from "resend";
// Only needed in hybrid mode
export const prerender = false;
const resend = new Resend(import.meta.env.RESEND_API_KEY);
export const POST: APIRoute = async () => {
const { data, error } = await resend.emails.send({
from: "Acme <[email protected]>",
to: ["[email protected]"],
subject: "Hello world",
html: "<strong>It works!</strong>",
});
if (error) {
return new Response(JSON.stringify({ error }), { status: 400 });
}
return new Response(JSON.stringify(data), { status: 200 });
};
TODO: card to https://github.com/resend/resend-astro-example