Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A rubygem for interacting with the Mandrill API

tag: v0.0.1

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .document
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .rspec
Octocat-spinner-32 .rvmrc
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Gemfile.lock
Octocat-spinner-32 Guardfile
Octocat-spinner-32 LICENSE.txt
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 VERSION
Octocat-spinner-32 mandrill.gemspec
README.rdoc

Mandrill Dependency Status

Mandrill is a Ruby gem that provides a wrapper for interacting with the Mandrill API. Remember that Mandrill has an excellent SMTP Headers API, which is often a better integration option, particularly if your app sends emails.

Installation

(sudo) gem install mandrill

Usage

To start with, you will need a Mandrill account as a developer so that you can register your app. People that want to use your application will also need to a create a Mandrill account (obviously) as well.

Register Your App

Login to your Mandrill account and click “register a new app” on the “Settings > Applications” page. Once your app is registered, you will get an “App Authentication ID”, which we refer to in this document at the “App ID”. You're now ready to get started.

Connect Your App

The first thing you will need to do is prompt your users to authorize the connection between your application and Mandrill. Once they are logged in, simply redirect them:

redirect_to Mandrill.authorization_url("your_app_id", "https://yourapp.com/mandrill/callback")

Once authorized successfully, a POST request will be sent to the redirect_url with a “key” parameter containing the API key for that user's Mandrill account. Be sure to store this key somewhere, as you will need it to run API requests later. If authorization fails for some reason, an “error” parameter will be present in the POST request, containing an error message.

def callback
  # POST /mandrill/callback
  if params[:key]
    current_user.mandrill_key = params[:key]
    current_user.save
    ...
  elsif params[:error]
    flash[:alert] = params[:error]
    ...
  end
end

As you can see, we are saving the key that Mandrill returns for the currently logged in user, and we have successfully connected this user account to Mandrill.

Interacting with the API

Once you have a valid API key (your own account password works) you can easily interact with the Mandrill API by passing in a hash:

m = Mandrill::API.new('api-key')
m.users :ping
m.users :senders
# Methods with dashes shouldn't be passed in as symbols
m.users 'disable-sender', {:domain => "exampledomain.com"}
m.users 'verify-sender', {:email => 'test@exampledomain.com'}
m.messages :send {:message => {:html => "HTML message text", :text => "message text"}...}

Errors

When an error is received an instance of Mandrill::API::Error will be returned so that you can rescue accordingly:

rescue Mandrill::API::Error > error
  ...

Contributing to Mandrill

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.

  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.

  • Fork the project.

  • Start a feature/bugfix branch.

  • Commit and push until you are happy with your contribution.

  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright

Copyright © 2011 Terra Firma Design & Consulting. See LICENSE.txt for further details.

Something went wrong with that request. Please try again.