SDKs overview

Postmark provides Software Development Kits (SDKs) and client libraries to simplify integration with its transactional email API. These libraries are designed to abstract the underlying HTTP RESTful API, allowing developers to interact with Postmark's services using native language constructs rather than direct HTTP requests. This approach reduces boilerplate code and streamlines tasks such as sending emails, managing sender signatures, handling templates, and processing inbound email or bounce webhooks.

The primary benefit of using an SDK is improved developer velocity; common API operations are encapsulated into functions or methods specific to a programming language. This can lead to fewer errors and a more consistent coding experience. SDKs often include features like automatic request signing, error handling, and object serialization/deserialization, which are crucial for reliable API interactions. Postmark maintains several official SDKs and supports a range of community-contributed libraries, ensuring broad language coverage for various development environments.

Developers can find comprehensive documentation for integrating Postmark's services, including detailed API specifications and SDK usage guides, within the official Postmark developer documentation.

Official SDKs by language

Postmark offers official SDKs for popular programming languages. These libraries are actively maintained by Postmark and provide a reliable interface for interacting with the Postmark API. They typically offer full coverage of API endpoints, including sending emails, managing templates, and handling bounce notifications. Using an official SDK ensures compatibility with the latest API versions and generally includes support for new features as they are released.

Official SDKs are usually the recommended choice for new projects due to their stability, official support, and comprehensive feature sets. They are rigorously tested and documented, minimizing integration challenges. Each SDK is tailored to the conventions and idioms of its respective language, making it feel natural to developers working in that ecosystem.

Language Package/Library Name Installation Command Maturity
Node.js postmark npm install postmark or yarn add postmark Official, Actively Maintained
Python postmark-py pip install postmark Official, Actively Maintained
Ruby postmark gem install postmark Official, Actively Maintained
PHP postmark/postmark composer require postmark/postmark Official, Actively Maintained
Java postmark-java Add to pom.xml (Maven) or build.gradle (Gradle) Official, Actively Maintained
C# Postmark Install-Package Postmark Official, Actively Maintained
Go go-postmark go get github.com/kevinburke/go-postmark Official, Actively Maintained

Installation

Installing Postmark SDKs typically follows the standard package management practices for each programming language. For Node.js, Python, Ruby, and PHP, this often involves a single command-line instruction using their respective package managers. Java and C# projects usually integrate libraries through dependency management tools like Maven, Gradle, or NuGet, where the library is declared in a configuration file.

Node.js Installation

To install the official Postmark Node.js library, you can use npm or Yarn:

npm install postmark
# or
yarn add postmark

Python Installation

The Postmark Python library is available via pip:

pip install postmark

Ruby Installation

For Ruby applications, the Postmark gem is installed using Bundler or direct gem installation:

gem install postmark
# Add to your Gemfile:
# gem 'postmark'

PHP Installation

PHP projects typically use Composer for dependency management:

composer require postmark/postmark

Java Installation

For Java, you'll need to add the Postmark dependency to your build configuration. For Maven, this goes into your pom.xml:

<dependency>
    <groupId>com.wildbit.java</groupId>
    <artifactId>postmark-java</artifactId>
    <version>1.15.0</version> <!-- Check for the latest version -->
</dependency>

For Gradle, add to your build.gradle:

implementation 'com.wildbit.java:postmark-java:1.15.0' // Check for the latest version

C# Installation

C# developers can install the Postmark NuGet package:

Install-Package Postmark

Go Installation

Go developers can retrieve the library using the go get command:

go get github.com/kevinburke/go-postmark

Quickstart example

This quickstart example demonstrates sending a simple transactional email using the Node.js Postmark SDK. The process involves initializing the client with your Postmark API token and then calling the sendEmail method with the necessary email details. This example focuses on basic email sending, which is a core function of the Postmark API and its SDKs.

Before executing this code, ensure you have your Postmark Server API Token. This token authenticates your requests to the Postmark API and should be kept secure. You can find your API tokens in your Postmark account settings under the Servers tab. For development, environment variables are a recommended method for managing API keys securely, as detailed in general API key security best practices.

Node.js Quickstart

// Import the Postmark client
const postmark = require("postmark");

// Initialize the Postmark client with your Server API Token
// It's recommended to use environment variables for API keys in production.
const client = new postmark.ServerClient(process.env.POSTMARK_API_TOKEN);

async function sendSingleEmail() {
  try {
    const response = await client.sendEmail({
      "From": "[email protected]", // Must be a verified sender signature in Postmark
      "To": "[email protected]",
      "Subject": "Hello from Postmark!",
      "HtmlBody": "<html><body><strong>Hello</strong> dear Postmark user.</body></html>",
      "TextBody": "Hello dear Postmark user.",
      "MessageStream": "outbound" // Optional: specify a message stream
    });
    console.log("Email sent successfully:", response);
  } catch (error) {
    console.error("Error sending email:", error);
  }
}

// Call the function to send the email
sendSingleEmail();

This snippet demonstrates how to configure the client and send a basic HTML and plain-text email. The From address must be a verified sender signature within your Postmark account to avoid sending failures. The MessageStream parameter is optional but useful for categorizing your email types, which aligns with Postmark's emphasis on separating transactional and broadcast email streams for improved deliverability.

Community libraries

Beyond the officially supported SDKs, the Postmark community has developed and maintains various client libraries for languages and frameworks not covered by official support. These libraries extend Postmark's reach and provide alternative implementations that might better suit specific project requirements or integrate more seamlessly with particular ecosystems. While not officially maintained by Postmark, many community libraries are robust and widely used.

Community libraries are often found on platforms like GitHub and are distributed via language-specific package managers. When choosing a community library, it's advisable to check its maintenance status, community activity, and compatibility with the latest Postmark API versions. Evaluating factors such as recent commits, open issues, pull request activity, and documentation quality can help assess a library's reliability. Resources like Mozilla Web Docs on HTTP requests provide foundational context for understanding how these libraries abstract underlying web API interactions.

Examples of community-contributed libraries and wrappers that have emerged over time include:

  • Elixir: A Postmark client for Elixir applications.
  • Rust: Wrappers for integrating Postmark into Rust projects.
  • ColdFusion (CFML): Libraries enabling Postmark integration for ColdFusion developers.
  • Dart/Flutter: Packages for sending emails via Postmark from Dart or Flutter applications.
  • Vue.js/React (frontend-focused): While direct API calls from frontend JavaScript are generally avoided for security reasons (due to exposing API keys), backend services built with languages like Node.js often integrate with Postmark, and frontend frameworks then interact with these backend services.

Developers are encouraged to explore Postmark's GitHub repositories and the broader developer community to discover these additional tools. Contributions to these open-source projects are also common, allowing developers to directly improve the tools they use.