Overview

Integration

User guide

API reference

Webhooks

Official Postmark libraries

These libraries are maintained by the developers at Postmark and are the easiest way to integrate Postmark with your application.

Don’t see the library you’re looking for?

If you can’t find the right library, check out our Community Libraries. If you’re looking for code to use with Postmark Inbound try our email parse code examples.

We’re building a wishlist of Postmark plugins, libraries, and integrations. If you have something you’d like to see, or would like to contribute, let us know!

Postmark Rails gem #

Configuring your Rails application

You will need the Postmark Rails gem for drop-in integration with ActionMailer.

Don’t forget to run the bundle install command every time you change something in your Gemfile.

The postmark_settings hash can contain all options supported by Postmark::ApiClient.

Add the postmark-rails gem to your Gemfile.

gem 'postmark-rails'

Save your Postmark Server API token to config/secrets.yml.

postmark_api_token: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

Set Postmark as your preferred mail delivery method via config/application.rb:

config.action_mailer.delivery_method = :postmark
config.action_mailer.postmark_settings = { :api_token => Rails.application.secrets.postmark_api_token }

Send an email

Here’s a simple example of how to send a single HTML email with open tracking enabled. Take a look at the README for more examples.

Example request

class TestMailer < ActionMailer::Base
  def hello
    mail(
      :subject => 'hello',
      :to  => '[email protected]',
      :from => '[email protected]',
      :html_body => '<strong>Hello from Postmark!<strong>',
      :track_opens => 'true'
    )
  end
end

Postmark Ruby gem #

Configuring your ruby application

You will need the Postmark gem to get started.

If you’re using Bundler, don't forget to run the bundle install command every time you change something in your Gemfile.

Install with Bundler

gem 'postmark'

Create an instance of Postmark::ApiClient

client = Postmark::ApiClient.new('server token')

Send an email

Here’s a simple example of how to send a single HTML email with open tracking enabled. Take a look at the README for more examples.

Example request

client.deliver(
  from: '[email protected]',
  to: '[email protected]',
  subject: 'hello',
  html_body: '<strong>Hello from Postmark!<strong>',
  track_opens: true
)

Postmark .NET #

Installation

The Postmark.NET NuGet package makes it easier to use the Postmark API from your .NET projects without having to build your own API calls.

If you need a strongly-named/signed .NET dll, you can use the Postmark-Strong .NET Nuget package which includes the JSON.NET dependancy built-in to avoid versioning conflicts.

Install with NuGet

PM> Install-Package Postmark

Import

using PostmarkDotNet;

Send an email

Here’s a simple example of how to send a single HTML email with open tracking enabled. Take a look at the wiki for more examples.

Example request

var message = new PostmarkMessage()
{
    To = "[email protected]",
    From = "[email protected]",
    TrackOpens = true,
    Subject = "A complex email",
    TextBody = "Plain Text Body",
    HtmlBody = "<html><body><img src=\"cid:embed_name.jpg\"/></body></html>",
    Tag = "business-message",
    Headers = new HeaderCollection{
        {"X-CUSTOM-HEADER", "Header content"}
    }
};

var imageContent = File.ReadAllBytes("test.jpg");
message.AddAttachment(imageContent, "test.jpg", "image/jpg", "cid:embed_name.jpg");

var client = new PostmarkClient("server token");
var sendResult = await client.SendMessageAsync(message);

Postmark Java #

Installation

The Postmark Java library makes it easier to use the Postmark API from your Java 8+ projects without having to build your own API calls.

Install with Maven

<dependency>
  <groupId>com.postmarkapp</groupId>
  <artifactId>postmark</artifactId>
  <version>{version}</version>
</dependency>

Send an email

Here’s a simple example of how to send a single email. Take a look at the wiki for more examples.

Example request

Message message = new Message("[email protected]", "[email protected]", "Hello from Postmark!", "Hello body");

ApiClient client = Postmark.getApiClient("server token");
MessageResponse response = client.deliverMessage(message);

Postmark PHP #

Installation

The Postmark PHP library is available as a Composer package on Packagist.org.

Install with composer

composer require wildbit/postmark-php

Import

require_once('./vendor/autoload.php');
use Postmark\PostmarkClient;

Send an email

Here’s a simple example of how to send a single email. Take a look at the wiki for more examples.

Example request

$client = new PostmarkClient("server token");

$sendResult = $client->sendEmail(
  "[email protected]",
  "[email protected]",
  "Test",
  "Hello from Postmark!");

Postmark Craft plugin #

Installation

The Postmark Craft plugin library is available as a Composer package on Packagist.org.

You can also install the plugin via the Craft Plugin Store

Go to the project directory

cd /path/to/my-project.test

Install with composer

composer require craftcms/postmark

Tell Craft to install the plugin

./craft install/plugin postmark

Configuration

Once the Postmark Craft plugin is installed, go to SettingsEmail in the Craft admin area, and change the Transport Type setting to Postmark.

Then enter your Postmark Server Token. This can be found on the ServerAPI Tokens page within your Postmark account.

If you wish to send email using a custom Message Stream, set the Message Stream ID. (The default transactional Message Stream will be used if this is left blank.)

When you’re done, hit Save.

Tip! Your Postmark Server Token and Message Stream ID can also be set using environment variables. See Environmental Configuration in the Craft docs to learn more about that.

Postmark Node.js #

Installation

The Postmark Node.js library is available as an npm package.

Install with npm

npm install postmark --save

Require

var postmark = require("postmark");

Send an email

Here’s a simple example of how to send a single email. Take a look at the documentation for more examples.

Example request

var serverToken = "xxxx-xxxxx-xxxx-xxxxx-xxxxxx";
var client = new postmark.ServerClient(serverToken);

client.sendEmail({
    "From": "[email protected]",
    "To": "[email protected]",
    "Subject": "Test",
    "TextBody": "Hello from Postmark!"
});

Nodemailer

You can optionally use nodemailer to send transactional emails through Postmark.

Postmark CLI #

Installation

Before you get started, install Node.js and make sure that your Postmark server and account tokens are handy.

From the command line, run:

npm i postmark-cli -g

Once npm does its thing, run the postmark command and you will see some high-level usage details. You’re all set!

Pro tip: You’ll be asked to authenticate by entering your server or account token each time you run a command. If you prefer, you can bypass this step by supplying tokens as environment variables.

Usage

After installation, type postmark in your command line to see a list of available commands. Check out the wiki for instructions on how to send emails, manage templates, or list servers.

$ postmark

  Commands:
    postmark email <command></command> [options]      Send an email
    postmark servers <command></command> [options]    Manage your servers
    postmark templates <command></command> [options]  Pull and push your templates

  Options:
    --version  Show version number
    --help     Show help

Further documentation

Postmark for WordPress #

Postmark for WordPress (fork on Github)

Installation

  1. Download the Postmark for WordPress Plugin
  2. Upload postmark directory to your /wp-content/plugins directory
  3. Activate the plugin in your WordPress admin
  4. In the WordPress admin, go to Settings > Postmark. You will then want to insert your Postmark details.
  5. Verify sending by entering a recipient email address you have access to and pressing the “Send Test Email” button.
  6. Once verified, then check “Enable” to override wp_mail and send using Postmark instead.

See the FAQ for answers to common questions.

Postmark Grunt #

Installation

The Postmark Grunt plugin is available as an npm package.

Install with npm

npm install grunt-postmark --save

Load task in Gruntfile

grunt.loadNpmTasks("grunt-postmark");

Send an email

Here’s a simple example of how to send an email. Take a look at the documentation for more examples.

Example task

grunt.initConfig({
  postmark: {
    options: {
      serverToken: "server token",
      from: "[email protected]",
      to: "[email protected]",
    }
    email: {
      subject: "Test",
      src: ["email-content.html"]
    }
  }
});

Postmark Zapier Actions #

Installation

The Postmark Zapier Actions are available on Zapier.

Configuration

Our Zapier Actions support both Send an Email and Send an Email With Template. When integrating with a Zapier Trigger, set the data into the respective fields when Zapier prompts, like To, From, Subject, etc.

If you wish to send email using a custom Message Stream, set the Message Stream ID. (The default transactional Message Stream will be used if this is left blank.)