SMTP.com Sendapi

Website: https://www.smtp.com/solutions/transactional-email-service-api/ API documentation: https://www.smtp.com/wp-content/uploads/SMTP-Transactional-API-Documentation.pdf

Requirements

Ruby 1.9.3 or above

Installation

gem install smtpcom-sendapi

Bundler

source 'https://rubygems.org'

gem 'smtpcom-sendapi', require: 'smtpcom/sendapi'

Usage

Setting your API key

Smtpcom::Sendapi.api_key = 'YOUR_API_KEY'

Campaigns

List all

 Smtpcom::Sendapi::Campaign.all

Create

campaign = Smtpcom::Sendapi::Campaign.new
campaign.name = 'MyCampaign'
campaign.save

puts campaign.id
#=> 556998d4130e7f0aa881b5c1

Find

campaign = Smtpcom::Sendapi::Campaign.find('556998d4130e7f0aa881b5c1')

# you can also get some stats from campaign object
puts campaign.opens
puts campaign.clicks
puts campaign.delivered
puts campaign.bounced

Delete

campaign.delete

Email

email = Smtpcom::Sendapi::Email.new

email.subject   = 'Hello world subj'
email.from      = '[email protected]'
email.body_text = 'Hello world'

# add recipients
email.add_recipient '[email protected]', 'John'
email.add_recipient '[email protected]'

# add headers
email.add_header 'X-CustomID', '81d4350b'

# add attachment
# can be attachment data in base64 format, or a url where the attachment can be downloaded from
email.add_attachment 'Image1', 'image/jpeg', base64_content

# send email
email.send

Allowed email attributes:

- subject
- body_html
- body_text
- template_id
- from
- from_name
- reply_to
- reply_to_name
- return_path
- recipients
- recipients_url
- default_recipient_data
- attachments
- campaign
- utm_codes
- email_headers

Templates

List all

Smtpcom::Sendapi::Template.all

Create

template = Smtpcom::Sendapi::Template.new
template.name = 'Template 1'
template.from = '[email protected]'
template.from_name = 'John'
template.subject = 'Hello world'
template.html = 'HTML email body'
template.save

puts template.id
#=> 156928d1130a7f0ab781b5c2

Find

template = Smtpcom::Sendapi::Template.find '156928d1130a7f0ab781b5c2'

Delete

template.delete

Senders

List all

Smtpcom::Sendapi::Sender.all

Reporting

Sends Report

# Parametes: time_start, time_finish, sender, campaign_id
report = Smtpcom::Sendapi::SendsReport.new time_start, time_finish

# return sends as array, accepts 2 optional parameters - count, page
report.all

# return failed sends as array, accepts 2 optional parameters - count, page
report.failed

Opens

# Parametes: time_start, time_finish, sender, campaign_id
report = Smtpcom::Sendapi::OpensReport.new time_start, time_finish

# return opens as array, accepts 2 optional parameters - count, page
report.all

# return opens as csv
report.csv

Clicks

# Parametes: time_start, time_finish, sender, campaign_id, url
report = Smtpcom::Sendapi::ClicksReport.new time_start, time_finish

# return clicks as array, accepts 2 optional parameters - count, page
report.all

# return clicks as csv
report.csv

Stats Summary

# Parametes: time_start, time_finish, sender, campaign_id, url
report = Smtpcom::Sendapi::StatsSummary.new time_start, time_finish

report.all

# in csv format
report.csv

Real Time Reporting

# get real time reporting settings
Smtpcom::Sendapi::RealTimeReporting.settings

# configure real time reporting
r = new Smtpcom::Sendapi::RealTimeReporting

r.queue_name            = 'MyQueue'
r.server_region         = 'us-west-2'
r.public_access_key     = 'public_key'
r.private_access_key    = 'private_key'
r.notify_opens          = false
r.notify_clicks         = true
r.notify_delivert_info  = false

r.save