Skip to content


Subversion checkout URL

You can clone with
Download ZIP
tree: 4def30c821
Fetching contributors…

Cannot retrieve contributors at this time

150 lines (98 sloc) 4.372 kb

postmark-rails gem

The Postmark Rails Gem is a drop-in plug-in for ActionMailer to send emails via Postmark, an email delivery service for web apps. The gem has been created for fast implementation and fully supports all of Postmark’s features.

Supported Rails Versions

  • lower than 2.3: could work, but not tested

  • 2.3 and higher

  • 3.0


sudo gem install postmark-rails


  • “postmark” gem version 0.8 and higher is required.

  • You will also need a Postmark account, server and sender signature set up to use it. To get an account, sign up at

Configuring your Rails application

Rails 3

Add this to your Gemfile: (change version numbers if needed)

gem 'postmark-rails', '0.4.0'

Don't forget to run “bundle install” command every time you change something in the Gemfile.

Add this to your config/application.rb:

config.action_mailer.delivery_method   = :postmark
config.action_mailer.postmark_settings = { :api_key => "your-api-key" }

Rails 2

Add this to config/environment.rb: do |config|


  config.gem 'postmark-rails'
  require    'postmark-rails'

  config.action_mailer.postmark_api_key = "your-api-key"
  config.action_mailer.delivery_method  = :postmark



For API details, refer to the developer documentation at

Tagging your deliveries

You can use a tag to categorize outgoing messages and attach application-specific information. Tagging the different types of email that you send lets you review statistics and bounce reports separately. Read more at

Rails 3

class TestMailer < ActionMailer::Base

  def tagged_message
      :subject => 'hello',
      :to      => '',
      :from    => '',
      :tag     => 'my-tag'


Rails 2

class SuperMailer < ActionMailer::Base

  def email
    from       ""
    subject    "Some marvelous email message"
    recipients ""
    tag        "my-another-tag"


Sending attachments

You can also send file attachments with Postmark. Read more here:

Rails 3

class TestMailer < ActionMailer::Base

  def message_with_attachment
      :subject              => 'hello',
      :to                   => '',
      :from                 => '',
      :postmark_attachments => ["/path/to/file")]


Rails 2

class SuperMailer < ActionMailer::Base

  def email
    from                 ""
    subject              "Some marvelous email message"
    recipients           ""
    postmark_attachments ["/path/to/file")]


You can pass either an array of File objects or a single object. Postmark will detect the file name automatically and send an attachment with the “application/octet-stream” content type. If you want more control on how attachments get formatted, you can pass Hash objects, which contain the custom settings such as file name or content-type. Here is an example:

# Don't forget to read your file and base64-encode it,
# before assigning it to "Content".
message.postmark_attachments = {
  "Name"        => "fancy-file-name.jpg",
  "Content"     => ["path/to/file") ].pack("m"),
  "ContentType" => "image/jpeg"

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so we don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history.

  • Send a pull request. Bonus points for topic branches.

Authors & Contributors

  • Petyo Ivanov

  • Ilya Sabanin

  • Hristo Deshev

  • Randy Schmidt

  • Chris Williams


Copyright © 2010 Wildbit LLC. See LICENSE for details.

Jump to Line
Something went wrong with that request. Please try again.