Send Emails with Next.js
Learn how to send transactional emails using PostStack and Next.js.
1. Install the SDK
bash
npm install @poststack/sdk2. Initialize the client
typescript
import PostStack from '@poststack/sdk';
const poststack = new PostStack(process.env.POSTSTACK_API_KEY!);3. Send an email
typescript
// app/api/send/route.ts
import { NextResponse } from 'next/server';
import PostStack from '@poststack/sdk';
const poststack = new PostStack(process.env.POSTSTACK_API_KEY!);
export async function POST() {
const { data, error } = await poststack.emails.send({
from: 'hello@yourdomain.com',
to: 'user@example.com',
subject: 'Hello from Next.js!',
html: '<h1>Welcome!</h1>',
});
if (error) return NextResponse.json({ error }, { status: 400 });
return NextResponse.json(data);
}Ready to send emails with Next.js?
Create a free account and get your API key in under a minute.