Skip to content

Getting Started

Patrick Graham edited this page Dec 4, 2019 · 13 revisions

Getting started with Postmark is very easy. In order to start using the full potential of Postmark Rails Gem, you will need to:

Account API token is needed only for admins, for managing account details like domains, signatures, etc. To read more about tokens, check out our developer docs.

Sending your first email

Sending email with Postmark is super easy, steps are the following.

Add postmark-rails to your Gemfile and run bundle install.

gem 'postmark-rails'

Rails 6

Save your Postmark Server API Token to config/credentials.yml.enc:

run rails secret, then run rails credentials:edit and add:

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.credentials.postmark_api_token }

Rails 3-5

Save your Postmark 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 }

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

After setting it all up, you can send emails like this:

class TestMailer < ActionMailer::Base

  def tagged_message
    mail(
      :subject => 'hello',
      :to      => '[email protected]',
      :from    => '[email protected]',
      :tag     => 'my-tag',
      :track_opens => 'true'
    )
  end

end

Next, we will check out more advanced sending techniques and other API features. Check out our wiki pages sidebar for details.

More examples

For more advanced examples, we suggest visiting Postmark Ruby Gem wiki pages.

Clone this wiki locally