0.0
No commit activity in last 3 years
No release in over 3 years
Rails Railtie for sending email, SMS, and push notifications using the Outbox gem.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.3.0
>= 12.3.3
~> 3.5.0
~> 3.5.2
~> 0.82.0

Runtime

~> 0.2.0
>= 5.0, < 7
 Project Readme

Outbox::Rails

Gem Version

Rails Railtie for sending email, SMS, and push notifications using the Outbox gem. Please view the Outbox documentation to understand the philosophy behind this interface and how to use it.

Installation

Add this line to your application's Gemfile:

gem 'outbox-rails'

And then execute:

$ bundle

Or install it yourself as:

$ gem install outbox-rails

Usage

Outbox::Notifier uses a very similar interface to ActionMailer.

First, define a notifier in app/notifiers:

class AccountNotifier < Outbox::Notifier
  default email: { from: 'noreply@myapp.com' },
          sms: { from: '+15551234567' }

  def welcome
    # Compose message types using the Outbox::Message interface
    email do
      subject 'Welcome to our App!'
    end

    sms do
      from '<shortcode_id>'
      # The "text" template will automatically be used for the body of the SMS.
      # But you can explicitly override by calling the #body method.
      body 'Welcome to our App!'
    end

    # Render the body of the message. This is analogous to ActionMailer::Base#mail,
    # but unlike in ActionMailer, #render_message is not required.
    render_message
  end
end

Send a message using the deliver method:

# Unlike ActionMailer, deliver takes an argument that defines the recipients
# for the message types you want to send.
AccountNotifier.welcome.deliver email: 'user@gmail.com', sms: '+15557654321'

Variants (New with Rails 4.1)

You can have different templates for each message type using variants. Right now, only the implicit template rendering is supported.

<!-- app/views/account_notifier/welcome.html+email.erb -->
<h1>Welcome!</h1>

<!-- app/views/account_notifier/welcome.text+email.erb -->
Welcome! (email)

<!-- app/views/account_notifier/welcome.text+sms.erb -->
Welcome! (sms)

Configuration

Configure Outbox using the config.outbox accessor during normal Rails configuration:

# config/application.rb
module Blog
  class Application < Rails::Application
    # Configure defautl email fields
    config.outbox.email_defaults = {
      from: 'from@example.com'
    }

    # Setup default email settings.
    config.outbox.default_email_client_settings = {
      smtp_settings: {
        address: 'smtp.gmail.com',
        port: 587,
        domain: 'example.com',
        user_name: '<username>',
        password: '<password>',
        authentication: 'plain',
        enable_starttls_auto: true
      }
    }
  end
end

# config/environments/test.rb
Blog::Application.configure do
  # Always use test client during tests
  config.outbox.use_test_client = true
end

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request