[Awesome Ruby Gem] Use postmark-rails gem to send your emails and track opens and tag your deliveries

postmark-rails

Postmark: Application Email Service with Exceptional Delivery - https://postmarkapp.com/ allows you to send your emails with high delivery rates. It also includes detailed statistics. In addition, Postmark can parse incoming emails which are forwarded back to your application.

The Postmark Rails Gem is a drop-in plug-in for ActionMailer to send emails via [Postmark - https://postmarkapp.com/)(https://postmarkapp.com/). The gem has been created for fast implementation and fully supports all of Postmark’s features - https://postmarkapp.com/why.

Prerequites

You will need a Postmark account - https://account.postmarkapp.com/login, server and sender signature (or verified domain) set up to use it. For details about setup, check out wiki pages - https://github.com/wildbit/postmark-rails/wiki/Getting-Started.

Installation

You can install it as a gem:

1
$ gem install postmark-rails

or add it into a Gemfile (Bundler):

1
2
3
4
5
# Gemfile

# wildbit/postmark-rails: Official integration library for using Rails and ActionMailer with the Postmark HTTP API
# https://github.com/wildbit/postmark-rails
gem 'postmark-rails', '0.21.0'

Then, run bundle install.

1
$ bundle install

Configuration

Rails 6

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

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

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

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

1
2
config.action_mailer.delivery_method = :postmark
config.action_mailer.postmark_settings = { api_token: Rails.application.credentials.postmark_api_token }

Usage

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

1
2
3
4
5
6
7
8
9
10
11
12
13
class TestMailer < ActionMailer::Base

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

end

See Home · wildbit/postmark-gem Wiki - https://github.com/wildbit/postmark-gem/wiki to learn more usages.

References

[1] wildbit/postmark-rails: Official integration library for using Rails and ActionMailer with the Postmark HTTP API - https://github.com/wildbit/postmark-rails

[2] postmark-rails | RubyGems.org | your community gem host - https://rubygems.org/gems/postmark-rails

[3] Getting Started · wildbit/postmark-rails Wiki - https://github.com/wildbit/postmark-rails/wiki/Getting-Started

[4] Email Sending · wildbit/postmark-rails Wiki - https://github.com/wildbit/postmark-rails/wiki/Email-sending

[5] Home · wildbit/postmark-gem Wiki - https://github.com/wildbit/postmark-gem/wiki

[6] Postmark: Application Email Service with Exceptional Delivery - https://postmarkapp.com/

[7] Track Opened Emails In Rails - https://www.dmitry-ishkov.com/2021/05/track-opened-emails-in-rails.html