Next.js
Send your first message from a Next.js project with the official Postwick library.
Use this ready-made prompt to wire Postwick into your project
Add the Postwick Next.js SDK to this project, read POSTWICK_API_KEY from the environment and send a test email to delivered@postwick.dev.Prerequisites
Before you begin you need:
A Postwick API key
Guide
- Install
Add the library to your project.
- npm
- yarn
- pnpm
- bun
npm install postwickyarn add postwickpnpm add postwickbun add postwick - Store your API key
Keep the key out of source control by putting it in an environment variable.
.env POSTWICK_API_KEY=pw_live_4f9c2e7a1b - Send an email
The smallest useful call takes a sender, a recipient, a subject and a body.
app/api/send/route.ts import { Postwick } from 'postwick'; const postwick = new Postwick(process.env.POSTWICK_API_KEY); export async function POST() { const { data, error } = await postwick.emails.send({ from: 'Lumen <hello@mail.lumen.dev>', to: ['ada@example.com'], subject: 'Welcome to Lumen', html: '<strong>You are in.</strong>', }); if (error) return Response.json({ error }, { status: 500 }); return Response.json(data); }
Examples
Updated
Was this page helpful?