Giter Site home page Giter Site logo

banana_peels's Introduction

BananaPeels

Interface for using MailChimp as a template repository for transactional emails. MailChimp campaigns define email content, using merge tags as placeholders for injectable content pieces.

Installation

Add this line to your application's Gemfile:

gem 'banana_peels'

And then execute:

$ bundle

Or install it yourself as:

$ gem install banana_peels

Usage

Campaign listing with ENV info (Rails)

app/controllers/campaigns_controller.rb:

class CampaignsController < ApplicationController

  def index
    @campaigns = BananaPeels.campaigns(ENV['MAILCHIMP_API_KEY'])
    @env_vars = Hash.new{|h,k| h[k] = [] }
    by_id = @campaigns.index_by(&:id)
    ENV.each do |k,v|
      @env_vars[v].push(k) if by_id[v]
    end
  end

end

app/views/campaigns/index.html.slim (http://slim-lang.com/, similar to haml):

h1 MailChimp Campaigns
table
  thead
    tr
      th Campaign Title
      th MailChimp ID
      td
        strong ENV Keys
        |  | Merge Tags
  tbody
    - @campaigns.each do |c|
      tr
        th = c.title
        td = c.id
        td
          strong = @env_vars[c.id].join(', ')
          |  |
          = c.merge_tags_in_content(exclude:[ :to_name ]).keys.join(', ')
      tr
        td rowspan="4"
        th Subject
        td = c.mailchimp_meta['subject']
      tr
        th From
        td = c.from
      tr
        th Text Content
        td = CGI.escapeHTML(c.text_content_unmerged).gsub("\n","\n<br>").html_safe
      tr
        th HTML Content
        td = c.html_content_unmerged

Sending transactional emails using a MailChimp Campaign as a template

app/mailers/user_mailer.rb:

class UserMailer < ActionMailer::Base
  include BananaPeels::MailerHelper

  def reset_password_instructions(record, token, opts={})
    user = User.find(record.id)
    mail_options = {
      to: BananaPeels.email_with_name("#{user.first_name} #{user.last_name}", user.email),
    }
    merge_tags = {
      'FIRST_NAME' => user.first_name,
      'LAST_NAME' => user.last_name,
      'RESET_PASSWORD_URL' => edit_user_password_url(reset_password_token: token),
    }
    banana_mail(ENV['RESET_PASSWORD_CAMPAIGN_ID'], mail_options, merge_tags, ENV['MAILCHIMP_API_KEY'])
  end

end

And then use the merge tags *|FIRST_NAME|*, *|LAST_NAME|*, *|RESET_PASSWORD_URL|* in your MailChimp Campaign.

Caching

To enable a rudimentary cache, set:

ENV['BANANA_PEELS_CACHE'] = 'ON'

This caches the responses for identical API & argument combinations, and modifies individual campaign metadata calls to retrieve the metadata for all campaigns.

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

banana_peels's People

Contributors

sbull avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

enddynayn

banana_peels's Issues

This violates MailChimps Acceptable Usage Policy

As published here:
http://mailchimp.com/legal/acceptable_use/

Sending transactional emails via MailChimp is prohibited and grounds for account suspension/termination.

You are, however, welcome to use the template portion of this along with our transactional email service, Mandrill, to send transactional emails based on MailChimp templates.

Mandrill really is a much cleaner fit anyway - for example:
http://help.mandrill.com/entries/21738467-Using-Mandrill-s-SMTP-integration-with-Web-Frameworks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.