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

1// src/routes/api/send/+server.ts
2import { Resent } from "resent.one";
3import { json } from "@sveltejs/kit";
4import { RESENT_API_KEY } from "$env/static/private";
5
6export async function POST() {
7 const resent = new Resent(RESENT_API_KEY);
8 const result = await resent.emails.send({
9 from: "Acme <noreply@yourdomain.com>",
10 to: "you@example.com",
11 subject: "Hello from SvelteKit",
12 html: "<strong>It works!</strong>",
13 });
14 return json(result);
15}

Next steps