Node.js
Send your first message from a Node.js project with the official Postwick library.
Use this ready-made prompt to wire Postwick into your project
Add the Postwick Node.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.
server.ts import { Postwick } from 'postwick'; const postwick = new Postwick(process.env.POSTWICK_API_KEY); const { data, error } = await postwick.emails.send({ from: 'Lumen <hello@mail.lumen.dev>', to: ['ada@example.com'], subject: 'Your receipt from Lumen', html: '<p>Thanks for your order, Ada.</p>', }); if (error) { console.error(error); }
Examples
Updated
Was this page helpful?