Frameworks
Next.js
Send from a Route Handler or Server Action.
npm install resendAdd to .env.local:
API_KEY=pw_xxxxxxxxx
RESEND_BASE_URL=https://post-waves.comimport { Resend } from 'resend';
const client = new Resend(process.env.API_KEY);
export async function POST(req: Request) {
const { email, name } = await req.json();
const { data, error } = await client.emails.send({
from: 'Acme <hello@yourdomain.com>',
to: [email],
subject: `Welcome, ${name}`,
html: `<p>Hi ${name}, thanks for signing up!</p>`,
});
if (error) return Response.json({ error }, { status: 400 });
return Response.json(data);
}'use server';
import { Resend } from 'resend';
const client = new Resend(process.env.API_KEY);
export async function sendWelcome(formData: FormData) {
await client.emails.send({
from: 'Acme <hello@yourdomain.com>',
to: [String(formData.get('email'))],
subject: 'Welcome!',
html: '<p>Thanks for signing up.</p>',
});
}Was this page helpful?Send feedback