All guides
Send Email from SvelteKit
Send emails from SvelteKit form actions and API routes
1. Install the SDK
npm install sendpigeon2. Set your API key
Add your SendPigeon API key to your environment variables:
SENDPIGEON_API_KEY=your_api_key_hereGet your API key from the dashboard.
3. Send your first email
// src/routes/contact/+page.server.ts
import type { Actions } from "./$types";
import { SendPigeon } from "sendpigeon";
import { SENDPIGEON_API_KEY } from "$env/static/private";
const client = new SendPigeon(SENDPIGEON_API_KEY);
export const actions: Actions = {
default: async ({ request }) => {
const data = await request.formData();
const email = data.get("email") as string;
const name = data.get("name") as string;
await client.emails.send({
from: "hello@yourdomain.com",
to: email,
subject: `Thanks for reaching out, ${name}!`,
html: `<h1>We got your message</h1><p>We'll get back to you soon.</p>`,
});
return { success: true };
},
};Features
- Works with SvelteKit form actions
- Server-side only (secure)
- Full TypeScript support
Ready to send emails?
Get started with 1,000 free emails per month.
Start for free