Sendable is a service that makes it simpler to design, manage and optimize your Transactional Emails. Sendable has created a Ruby gem sendable
that communicates with our REST API for sending your transactional emails.
Ruby on Rails developers use the ActionMailer interface for sending emails. This gem, sendable_rails
implements a small layer over the sendable
gem that provides an API similar to ActionMailer.
Add this line to your application's Gemfile:
gem 'sendable_rails'
And then execute:
$ bundle
Or install it yourself as:
$ gem install sendable_rails
There are 2 ways to set up Sendable. You can either set the API key in an environment variable, or pass it in an initializer.
Add the following environment variable to your application. You can get your API key from the settings page of your Sendable project dashboard.
SENDABLE_API_KEY
=YOUR API KEY
If you don't want to set an environment variable, create a file config/initializers/sendable.rb
and put this in there:
Sendable.config do |config|
config.api_key = 'YOUR API KEY'
end
The only changes required in your existing mail
method are:
- Replace
mail
withsendable_mail
- Pass a
template
key that you can get from your Sendable project dashboard - Instance variables will be passed to your email template
Everything else will work as expected. Here is a before and after comparison:
class UserMailer < ActionMailer::Base
default from: 'no-reply@example.com'
def welcome(user)
@user = user
mail( to: @user.email, subject: "Welcome to My Awesome Site!" )
end
end
class UserMailer < ActionMailer::Base
default from: 'no-reply@example.com'
def welcome(user)
@user = user
sendable_mail to: @user.email, template: 1
end
end
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
The gem is available as open source under the terms of the MIT License.