Maktoub is a Ruby on Rails engine for email newsletters.
-
Write your newsletter as you would write any view (erb partial)
-
Maktoub sends your email in multipart as both html and text
# Add this line to your Gemfile gem 'maktoub'
Then ‘bundle install’
In config initializers create a maktoub.rb file and configure your settings. Example below:
Maktoub.from = "Test Sender <maktoub@example.com>" # the email the newsletter is sent from Maktoub.twitter_url = "http://twitter.com/#!/twitter" # your twitter page Maktoub.facebook_url = "http://www.facebook.com/facebook" # your facebook oage Maktoub.subscription_preferences_url = "http://example.com/manage_subscriptions" #subscribers management url Maktoub.logo = "logo.jpg" # path to your logo asset Maktoub.home_domain = "example.com" # your domain Maktoub.app_name = "Maktoub" # your app name # pass a block to subscribers_extractor that returns an object that reponds to :name and :email # (fields can be configured as shown below) require "ostruct" Maktoub.subscribers_extractor do users = [] (1..5).each do |i| users << OpenStruct.new({name: "tester#{i}", email: "test#{i}@example.com"}) end return users end # uncomment lines below to change subscriber fields that contain email and # Maktoub.email_field = :address # Maktoub.name_field = :nickname
Create a newsletter as a normal view partial in app/views/maktoub/newsletters/. The subject of the newsletter will be automatically deduced from the partial’s name.
Maktoub comes with two rake tasks to allow you to:
-
send a test message to the “from” address of your newsletter.
rake maktoub:test
-
publish the newsletter to all your subscribers. If you have delayed_job installed then it will use it to deliver each email as a background job
rake maktoub:mail
Alternatively you have access to a Maktoub::NewsletterMailer ActionMailer object with a publish method
Maktoub::NewsletterMail.publish('my_newsletter_partial', :name => 'User name', :email => 'user@example.com')
To be able to view your newsletter in a browser add it to routes.rb.
# mount the engine at a path of your choice. # you would access the newsletter at: http://example.com/newsletter/my_awesome_newletter mount Maktoub::Engine => "/"