npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@popovmp/postmark-email

v1.1.1

Published

Postmark Email

Readme

Postmark Email

A lightweight Node.js library for sending emails via Postmark with TypeScript support, input validation, and automatic retry functionality.

Features

  • TypeScript Support: Full type definitions included
  • Input Validation: Validates email addresses and required fields
  • Automatic Retries: Configurable retry mechanism for network failures
  • Error Handling: Comprehensive error reporting and logging
  • ESM Support: Native ES modules
  • Lightweight: Minimal dependencies

Installation

npm install @popovmp/postmark-email

Quick Start

import { sendPostMarkEmail } from "@popovmp/postmark-email";

// Configure Postmark settings
const postmarkModel = {
    token: "YOUR-POSTMARK-SERVER-TOKEN",
    from: "[email protected]",
    url: "https://api.postmarkapp.com/email",
    retry: 60000, // Retry delay in milliseconds
};

// Compose your email
const mailModel = {
    to: "[email protected]",
    subject: "Welcome to our service!",
    message: "Thank you for signing up. We're excited to have you!",
    replyTo: "[email protected]", // Optional
    tag: "welcome", // Optional - for tracking
};

// Send the email
try {
    await sendPostMarkEmail(postmarkModel, mailModel);
    console.log("Email sent successfully!");
} catch (error) {
    console.error("Failed to send email:", error.message);
}

API Reference

sendPostMarkEmail(postmarkModel, mailModel, retryCount?, maxRetries?)

Sends an email via Postmark with automatic retry functionality.

Parameters

postmarkModel: PostmarkModel

Configuration object for Postmark service:

| Property | Type | Required | Description | |----------|----------|----------|-------------| | token | string | ✅ | Your Postmark server token | | from | string | ✅ | Sender email address | | url | string | ✅ | Postmark API endpoint (usually https://api.postmarkapp.com/email) | | retry | number | ✅ | Retry delay in milliseconds for failed requests |

mailModel: MailModel

Email content and recipient information:

| Property | Type | Required | Description | |-----------|----------|----------|-------------| | to | string | ✅ | Recipient email address (validated) | | subject | string | ✅ | Email subject line | | message | string | ✅ | Email body (plain text) | | replyTo | string | ❌ | Reply-to email address (validated if provided) | | tag | string | ❌ | Tag for email tracking and organization |

retryCount?: number

Current retry attempt (default: 0). Used internally for retry mechanism.

maxRetries?: number

Maximum number of retry attempts (default: 3).

Returns

Promise<void> - Resolves on successful email sending, rejects on failure.

Throws

  • Error - On validation failures, network errors, or Postmark API errors

Error Handling

The library provides comprehensive error handling for common scenarios:

try {
    await sendPostMarkEmail(postmarkModel, mailModel);
} catch (error) {
    if (error.message.includes("Validation error")) {
        // Handle input validation errors
        console.error("Invalid input:", error.message);
    } else if (error.message.includes("Network error")) {
        // Handle network connectivity issues
        console.error("Network problem:", error.message);
    } else if (error.message.includes("Postmark Error")) {
        // Handle Postmark API errors
        console.error("Postmark API issue:", error.message);
    } else {
        // Handle other errors
        console.error("Unexpected error:", error.message);
    }
}

Validation

The library automatically validates:

  • Email addresses: Both to and replyTo fields must be valid email formats
  • Required fields: All mandatory fields must be present and non-empty strings
  • Data types: Ensures correct types for all parameters

Retry Mechanism

The library includes automatic retry functionality:

  • Network failures (status code 0) trigger automatic retries
  • Configurable delay: Set via postmarkModel.retry (in milliseconds)
  • Maximum attempts: Defaults to 3, configurable via maxRetries parameter
  • Exponential backoff: Not implemented (uses fixed delay)

TypeScript Support

Full TypeScript definitions are included:

interface PostmarkModel {
    token: string;
    from: string;
    url: string;
    retry: number;
}

interface MailModel {
    to: string;
    subject: string;
    message: string;
    replyTo?: string;
    tag?: string;
}

Examples

Basic Email

const postmarkModel = {
    token: "your-postmark-token",
    from: "[email protected]",
    url: "https://api.postmarkapp.com/email",
    retry: 30000,
};

const mailModel = {
    to: "[email protected]",
    subject: "Order Confirmation",
    message: "Your order #12345 has been confirmed and will ship soon.",
};

await sendPostMarkEmail(postmarkModel, mailModel);

Email with Tags and Reply-To

const mailModel = {
    to: "[email protected]",
    subject: "Password Reset",
    message: "Click the link below to reset your password...",
    replyTo: "[email protected]",
    tag: "password-reset",
};

await sendPostMarkEmail(postmarkModel, mailModel);

Custom Retry Configuration

// Send with custom retry settings
await sendPostMarkEmail(
    postmarkModel, 
    mailModel, 
    0,  // Starting retry count
    5   // Maximum 5 retry attempts
);

Dependencies

Development

# Run tests
npm test

# Run linting
npm run lint

# Type checking
npm run check

License

MIT

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Changelog

v1.0.0

  • Initial release
  • TypeScript support
  • Input validation
  • Automatic retry mechanism
  • Comprehensive error handling