Postmark

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 this to your gemfile

gem 'postmark-rails'

Add this to your config/application.rb file:

config.action_mailer.delivery_method = :postmark
config.action_mailer.postmark_settings = { :api_key => "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

class TestMailer < ActionMailer::Base
  def message
    mail(
      :subject => 'hello',
      :to  => 'receiver@example.com',
      :from => 'sender@example.com',
      :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: 'sender@example.com',
  to: 'receiver@example.com',
  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 2, 3.x, and 4.x 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 = "recipient@example.com",
    From = "sender@example.com",
    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 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(
  "sender@example.com", 
  "receiver@example.com", 
  "Test",
  "Hello from Postmark!");

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 client = new postmark.Client("server token");

client.sendEmail({
    "From": "sender@example.com", 
    "To": "receiver@example.com", 
    "Subject": "Test", 
    "TextBody": "Hello from Postmark!"
});

Postmark WordPress plugin

Postmark Approved WordPress Plugin (fork on Github) maintained by Andy Yates & Alex Hillman

Installation

  1. Download the Postmark 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.