Ruby bindings for sending email via the sendwithus API.
gem install send_with_us
or with Bundler:
gem 'send_with_us'
bundle install
For any Ruby project:
require 'rubygems'
require 'send_with_us'
begin
obj = SendWithUs::Api.new( api_key: 'YOUR API KEY', debug: true )
# only required params
result = obj.send_with(
'EMAIL_ID',
{ address: "[email protected]" })
puts result
# with all optional params
result = obj.send_with(
'email_id',
{ name: 'Matt', address: '[email protected]' },
{ company_name: 'TestCo' },
{ name: 'Company',
address: '[email protected]',
reply_to: '[email protected]' })
puts result
# full cc/bcc support
result = obj.send_with(
'email_id',
{ name: 'Matt', address: '[email protected]' },
{ company_name: 'TestCo' },
{ name: 'Company',
address: '[email protected]',
reply_to: '[email protected]' },
[
{ name: 'CC',
address: '[email protected]' }
],
[
{ name: 'BCC',
address: '[email protected]' },
{ name: 'BCC2',
address: '[email protected]' }
])
puts result
# Attachment support
result = obj.send_with(
'email_id',
{ name: 'Matt', address: '[email protected]' },
{ company_name: 'TestCo' },
{ name: 'Company',
address: '[email protected]',
reply_to: '[email protected]' },
[],
[],
['path/to/file.txt'])
puts result
# Set ESP account
# See: https://help.sendwithus.com/support/solutions/articles/1000088976-set-up-and-use-multiple
result = obj.send_with(
'email_id',
{ name: 'Matt', address: '[email protected]' },
{ company_name: 'TestCo' },
{ name: 'Company',
address: '[email protected]',
reply_to: '[email protected]' },
[],
[],
[],
'esp_MYESPACCOUNT')
puts result
rescue => e
puts "Error - #{e.class.name}: #{e.message}"
end
require 'rubygems'
require 'send_with_us'
begin
obj = SendWithUs::Api.new( api_key: 'YOUR API KEY', debug: true )
result = obj.drip_unsubscribe('[email protected]')
puts result
rescue => e
puts "Error - #{e.class.name}: #{e.message}"
end
For a Rails app, create send_with_us.rb
in /config/initializers/
with the following:
SendWithUs::Api.configure do |config|
config.api_key = 'YOUR API KEY'
config.debug = true
end
In your application code where you want to send an email:
begin
result = SendWithUs::Api.new.send_with('email_id', { address: '[email protected]' }, { company_name: 'TestCo' })
puts result
rescue => e
puts "Error - #{e.class.name}: #{e.message}"
end
Take a look at our Mailer that you can use to replace ActionMailer
The following errors may be generated:
SendWithUs::ApiInvalidEndpoint - the target URI is probably incorrect or email_id is invalid
SendWithUs::ApiInvalidKey - the sendwithus API key is invalid
SendWithUs::ApiBadRequest - the API request is invalid
SendWithUs::ApiConnectionRefused - the target URI is probably incorrect
SendWithUs::ApiUnknownError - an unhandled HTTP error occurred
Build gem with
gem build send_with_us.gemspec
Publish gem with
gem push send_with_us-VERSION.gem