SocketLabs Gem

Ruby gem for sending email through SocketLabs Email On-Demand. SocketLabs Email On-Demand is a managed email delivery service featuring high deliverability, message tracking and rich statistics and reporting through a web control panel and API.

A SocketLabs Email On-Demand account is required to use this API. Basic SocketLabs Email On-Demand accounts are available for free, with paid plans available for more features and messages per month.

For more information visit: www.socketlabs.com

Installation

sudo gem install socketlabs

Bare Bones Example

# You can get the URL and serverToken from your control panel
require 'socketlabs'
SocketLabs.url="https://api.socketlabs.com/v1/email/send"
SocketLabs.serverToken = "13451345"  

# You can instantiate the EmailMessage object and work with its properties and methods
msg = SocketLabs::EmailMessage.new
msg.from = '[email protected]'
msg.to = '[email protected]'
msg.subject = 'Subject of message'
msg.textBody = 'This is the text message body.'
msg.send

Other cool stuff you can do

# You can specify an HTML body in addition to or instead of a text body
msg.htmlBody = '<html><body>This is the text message body.</html></body>'

# You can merge data to a template you create online in the SocketLabs Email On-Demand control panel
msg.templateId="23498723"
msg.templateData={:firstName=>'John', :accountNumber=>'12345'}

# Templates even support data collections such as lines on an invoice
msg.templateData={:invoiceNumber=>'1234', :items=>{'Blue Widget'=>15, 'Red Widget'=>10}}

# When using the template and merge engine, you can even request a copy of the merged html and/or text body in the response.
msg.showme=true

# You can tag your messages with a campaign identifier and a message identifier which will show up in our online delivery reports and stats
msg.messageId='123456'
msg.mailingId='Campaign 9'

# You can specify custom headers
msg.headers = {:X-MyHeader=>'Value', :List-Unsubscribe=>'Value'}

# Or just do a quick and dirty one liner to construct and send an email
SocketLabs::SendQuickMessage("[email protected]", "[email protected]", "subject", "body")

Copyright ©2010 SocketLabs, Inc.