mad_mimi_two

courtesy scott sproule www.estormtech.com

Why use Mad Mimi rather than action mailer? Primarily since it allows you to separate the design of your emails from the code. Create nice designs on mad mimi, add analytics tracking urls, and update the contents of promotions via the mad mimi interface rather than trying to do it all in your code.

DESCRIPTION:

Using Mad Mimi on rails 3. All of the elegant portions of the code are based on the original github.com/redsquirrel/mad_mimi_mailer by ethangunderson. (MadMimiTwo also runs in Rails 2)

All of the terrible stuff is by me. Apologies for taking an elegant solution and just crafting something that works.

FEATURES/PROBLEMS:

  • FIX (list of features or problems)

This has only been tested on Ruby 1.8.7. Testing on Ruby 1.9 required. Currently tested and working with rails 3 beta and Rails 2 (same code works)

SYNOPSIS:

API CONFIG

Setup your api key in application.rb (at the end of the file, after the end for the config) require ‘mad_mimi_two’ #not certain why this is needed…sigh.

MadMimiTwo::MadMimiMessage.api_settings = {
   :username => '[email protected]',
   :api_key => 'your api key'
 }

GEMFILE:

gem ‘httpclient’ gem ‘mad_mimi_two’

MIMI MODEL

set up model in your rails model directory (something like the following) class MadMimi < MadMimiTwo::MadMimiMessage

def self.mimi_promotion(tpromotion,tuser,thashvalues,cclist, tsubj)
  msg=MadMimiTwo::MadMimiMessage.new do
    	  subject    tsubj
   to tuser
   cc          cclist
   promotion   tpromotion  #[MAD MIMI PROMOTION NAME]
   from       '[email protected]'
   bcc        ["[email protected]", "[email protected]"]
   email_placeholders        thashvalues  # [VALUES THAT NEED TO BE INSERTED AT MAD MIMI EMAIL  these are the values in {} in the mad mimi email that you want replaced  eg {:url='www.estormtech.com'}]
   content_type "text/html" 
 end
 msg.deliver_mimi_message  # will return the mimi id -like 1151306886 if all ok.
end

end

to use it: MadMimi.mimi_promotion(‘promoname’,‘[email protected]’,href="www.estormtech.com">www.estormtech.com’,‘[email protected]’,‘demo subject’) this will return a ID from mad mimi like 1151260526

IGNORE: warning: peer certificate won’t be verified in this SSL session

Mail::Message

As this is subclassed from Mail::Message I believe that other ways to create the message will also work (such as passing in hash, etc (see the documentation))

Check Status of sent message

		t=MadMimiTwo::MadMimiMessage.new

r=t.check_status(‘1159748168’) # this is value from ID r is ‘Sent’

RAILS 2:

NOTE, The same code works in Rails 2 as well. except that you need to change environment.rb

config.gem 'mad_mimi_two'

and at the end of the environment.rb file: insert the api settings.

REQUIREMENTS:

gem activesupport gem mail (but both of these needed for rails)

INSTALL:

gem install mad_mimi_two (it is now up on rubygems.org)

RAILS TESTING:

Apologies but this needs work. I have simple tests in my application but nothing spectacular.

DeskTop TESTING:

There is a small command line program where you can test your api settings etc. ‘send_mimi.rb’ example usage is as follows: (NOTE key is in quotes)

send_mimi.rb -e [email protected] -p new_crm -k ‘keyvalue’ -u [email protected] -s testing -h “{:user => ‘test’, :url => ‘test.estormtech.com’ }” # email is [email protected] # promotion is new_crm # api key zzzzzz # username is qqqqq # subject is testing # hashvalues are {:user => ‘test’, :url => ‘test.estormtech.com’ } warning: peer certificate won’t be verified in this SSL session 1282604803 # this is the return value from mad mimi

Get promotion list

t=MadMimiTwo::MadMimiMessage.new
r=t.get_promotions()

returns a hash of promotions on your account

Add email address to list (eg for drip lists)

t=MadMimiTwo::MadMimiMessage.new r=t.add_email(‘driplisttest’,“[email protected]”)

LICENSE:

(The MIT License)

Copyright © 2010 FIXME full name

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.