Skip to main content

Prerequisites

To get the most out of this guide, you’ll need to:

1. Install

shell
gem install sendpost_ruby_sdk

2. Getting Started

Ruby
require 'sendpost_ruby_sdk'

# Configure API key
config = Sendpost::Configuration.new
config.host = 'https://api.sendpost.io/api/v1'
config.api_key['X-SubAccount-ApiKey'] = 'your_sub_account_api_key'

# Create API client
api_client = Sendpost::ApiClient.new(config)
email_api = Sendpost::EmailApi.new(api_client)

# Create email message
email_message = Sendpost::EmailMessageObject.new

from = Sendpost::EmailMessageFrom.new
from.email = '[email protected]'
email_message.from = from

to = Sendpost::EmailMessageToInner.new
to.email = '[email protected]'
email_message.to = [to]

email_message.subject = 'Hello World'
email_message.html_body = '<strong>it works!</strong>'

begin
  result = email_api.send_email(email_message)
  puts "Email sent! Message ID: #{result[0].message_id}"
rescue Sendpost::ApiError => e
  puts "Exception when calling EmailApi->send_email: #{e}"
end

3. Try it for yourself

Ruby Example

See detailed sdk example