Sign inGet Started

Ruby SDK

Send email with Sinatra

Use Parcel Wing from a small Sinatra app, Rack endpoint, or local email-testing form.

Install the SDK

The official Ruby SDK is published as parcelwing.

Terminal

gem install parcelwing

Send from a route

Create the client once during app boot and reuse it from route handlers.

app.rb

require "bundler/setup"
require "json"
require "parcelwing"
require "sinatra/base"
 
class App < Sinatra::Base
configure do
set :parcelwing, ParcelWing::Client.new(
api_key: ENV.fetch("PARCELWING_API_KEY")
)
end
 
post "/send-welcome" do
payload = JSON.parse(request.body.read)
 
emails = settings.parcelwing.emails.send(
from: ENV.fetch("PARCELWING_FROM_EMAIL"),
to: payload.fetch("email"),
template_alias: "welcome",
template_params: { first_name: payload["first_name"] || "friend" }
)
 
content_type :json
{ id: emails.first.fetch("id") }.to_json
rescue ParcelWing::Error => error
status error.status || 500
{ error: error.code, request_id: error.request_id }.to_json
end
end

Example app

The official Ruby example repository is a tiny Sinatra app with a browser form for sending test email.

Open Sinatra example