Skip to content

Latest commit

 

History

History
64 lines (40 loc) · 2.19 KB

README-mandrill.markdown

File metadata and controls

64 lines (40 loc) · 2.19 KB

Mailchimp::Mandrill

Mailchimp::Mandrill is a simple API wrapper for the Mailchimp Mandrill API.

##Requirements

A MailChimp account and a Mandrill specific API key.

Note, to be able to send messages, you'll have to click an e-mail in a message sent to you the first time you try to use that sender.

##Usage

There are a few ways to use Mandrill.

You can create an instance of the API wrapper:

mandrill = Mailchimp::Mandrill.new("your_api_key")

You can set your api_key globally and call class methods:

Mailchimp::Mandrill.api_key = "your_api_key"
Mailchimp::Mandrill.user_senders(...)

You can also set the environment variable 'MAILCHIMP_MANDRILL_API_KEY' and Mandrill will use it when you create an instance:

mandrill = Mailchimp::Mandrill.new

To check if your api_key is valid:

mandrill.valid_api_key?
Mailchimp::Mandrill.valid_api_key?("your_api_key")

Sending a message

Send a message so a single email:

response = mandrill.messages_send({
    :message      => { 
        :subject => 'your subject', 
        :html => '<html>hello world</html>', 
        :text => 'hello world', 
        :from_name => 'John Smith', 
        :from_email => '[email protected]', 
        :to => ['[email protected]']
    }
})

Calling other methods is as simple as calling API methods directly on the Mandrill instance (e.g. mandrill.users_verify_sender(...)). Check the API documentation) for more information about API calls and their parameters.

Plugging into ActionMailer

You can tell ActionMailer to send mail using Mandrill by adding the follow to to your config/application.rb or to the proper environment (eg. config/production.rb) :

config.action_mailer.delivery_method = :mailchimp_mandrill
config.action_mailer.mailchimp_mandrill_settings = {
      :api_key => "your_mailchimp_mandrill_apikey",
      :track_clicks => true,
      :track_opens  => true, 
      :from_name    => "Change Me"
 }

These setting will allow you to use ActionMailer as you normally would, any calls to mail() will be sent using Mandrill