Using the Mandrill Ruby Gem

The official Mandrill Ruby gem provides a lightweight wrapper around the Mandrill API, and mirrors the structure and functionality of the Mandrill API.

The gem assumes your API key is stored as an environment variable called MANDRILL_APIKEY.

To send a simple HTML message with the messages/send API endpoint, you'll create a new instance of the class and then pass a single parameter, the message:

require 'mandrill'  
m =
message = {  
 :subject=> "Hello from the Mandrill API",  
 :from_name=> "Your name",  
 :text=>"Hi message, how are you?",  
     :email=> "",  
     :name=> "Recipient1"  
 :html=>"<html><h1>Hi <strong>message</strong>, how are you?</h1></html>",  
sending = m.messages.send message  
puts sending

Rendering a template using templates/render:

require 'mandrill'
m =

rendered = m.templates.render 'MyTemplate', [{:name => 'main', :content => 'The main content block'}]
puts rendered['html'] # print out the rendered HTML