SvelteKit

Send email from SvelteKit form actions and API routes.

Send email from SvelteKit form actions and API routes.

Install

npm i resent.one

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

Send an email

// src/routes/api/send/+server.ts
import { Resent } from "resent.one";
import { json } from "@sveltejs/kit";
import { RESENT_API_KEY } from "$env/static/private";
export async function POST() {
const resent = new Resent(RESENT_API_KEY);
const result = await resent.emails.send({
from: "Acme <noreply@yourdomain.com>",
to: "you@example.com",
subject: "Hello from SvelteKit",
html: "<strong>It works!</strong>",
});
return json(result);
}

Next steps