Postmark Node.js Library

4.0.7 · active · verified Wed Apr 22

The `postmark` package is the official Node.js client library for interacting with the Postmark HTTP API, facilitating robust email sending and parsing capabilities within Node.js applications. It provides high delivery rates, comprehensive bounce and spam processing, and detailed email statistics. The current stable version is 4.0.7, which has recently updated its underlying HTTP client (`axios`). The library sees frequent patch releases to keep dependencies current and make minor model adjustments, with major version increments typically aligned with Node.js End-of-Life (EOL) cycles. Its key differentiators include being an official, actively maintained client with full support for Postmark's REST API, including features for both sending transactional emails and parsing incoming emails.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to initialize the Postmark `ServerClient` and send a basic transactional email using environment variables for the API token.

import { ServerClient } from 'postmark';

const POSTMARK_SERVER_TOKEN = process.env.POSTMARK_SERVER_TOKEN ?? '';

if (!POSTMARK_SERVER_TOKEN) {
  console.error('POSTMARK_SERVER_TOKEN environment variable is not set.');
  process.exit(1);
}

const client = new ServerClient(POSTMARK_SERVER_TOKEN);

async function sendExampleEmail() {
  try {
    const response = await client.sendEmail({
      From: 'sender@example.com',
      To: 'recipient@example.com',
      Subject: 'Hello from Postmark.js!',
      TextBody: 'Hello, this is a test email sent using the official Postmark Node.js library!',
      HtmlBody: '<html><body><strong>Hello</strong>, this is a test email sent using the official Postmark Node.js library!</body></html>',
      MessageStream: 'outbound'
    });
    console.log('Email sent successfully:', response);
  } catch (error) {
    console.error('Failed to send email:', error);
    if (error instanceof Error) {
      console.error('Error message:', error.message);
    }
  }
}

sendExampleEmail();

view raw JSON →