Delivery

Delivery is a Rails engine, providing a simple mailing list.

Currently, Delivery supports:

  • only one mailing list
  • new subscriptions to the mailing list
  • email notifications of new subscribers to the mailing list

Right now, the features are few but they suit my needs!

Installation

Delivery is a Rails engine. It works with versions of Rails greater than 2.3.

In config/environment.rb:


	config.gem "louismrose-delivery", 
    :lib     => 'delivery', 
    :source  => 'http://gems.github.com', 
    :version => '0.1.2'

Vendor the gem:


    rake gems:install
    rake gems:unpack

Environment

Define a DELIVERY_OPTIONS constant in your environment files. Delivery uses Pony to send email notifications. You must specify all the necessary Pony options (other than subject and body).

An example using SMTP (note the use of :password, rather than :pass which the Pony documentation incorrectly suggests):


	DELIVERY_OPTIONS = {
	  :to => '[email protected]',
	  :from => '[email protected]',
	  :via => :smtp,
	  :smtp => {
      :host     => 'localhost',
      :port     => '25',
      :user     => 'mailer+example.com',
      :password => 'secret',
      :auth     => :login,
      :domain   => 'www.example.com'
    }
  }

For a full discussion of these options, see the Pony documentation.

Define root_url to something in your config/routes.rb:


    map.root :controller => 'home'

Usage

Delivery adds a couple of routes to its host application:


  > rake routes
  subscriptions POST /subscriptions(.:format)           {:action=>"create", :controller=>"delivery/subscriptions"}
  new_subscription GET  /subscriptions/new(.:format)       {:action=>"new", :controller=>"delivery/subscriptions"}

After running script/server, navigate to: http://localhost:3000/subscriptions/new. Submitting the form on this page causes an email to be sent to DELIVERY_OPTIONS[:to].

Testing

To simplify testing, DELIVERY_OPTIONS[:via] may be set to :test. This causes Delivery::SubscriptionsController to buffer any new subscription notification. The buffer can be accessed through the email instance variable on Delivery::SubscriptionsController. For more details, see the example in test/controllers/subscriptions_controller_test.rb.

Copyright © 2009 Louis Rose, released under the MIT license