= Mandrill {}[http://travis-ci.org/terra-firma/mandrill] {Dependency Status}[https://gemnasium.com/terra-firma/mandrill] Mandrill is a Ruby gem that provides a wrapper for interacting with the {Mandrill API}[http://mandrillapp.com/api/docs/index.html]. Remember that {Mandrill}[http://mandrillapp.com] has an excellent {SMTP Headers API}[http://help.mandrill.com/customer/portal/articles/456744-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}[http://help.mandrill.com/customer/portal/articles/456476-setup-and-general-information] 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}[http://help.mandrill.com/customer/portal/articles/456476-setup-and-general-information] (obviously) as well. === Register Your App {Login to your Mandrill account}[https://mandrillapp.com] and click "{register a new app}[https://mandrillapp.com/app/register]" 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}[https://mandrillapp.com]. 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}[https://mandrillapp.com] 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}[https://mandrillapp.com/settings] works) you can easily interact with the {Mandrill API}[http://mandrillapp.com/api/docs/index.html] 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 (c) 2011 Terra Firma Design & Consulting. See LICENSE.txt for further details.