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::Baseconfigure doset :parcelwing, ParcelWing::Client.new(api_key: ENV.fetch("PARCELWING_API_KEY"))endpost "/send-welcome" dopayload = 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_jsonrescue ParcelWing::Error => errorstatus error.status || 500{ error: error.code, request_id: error.request_id }.to_jsonendend
Example app
The official Ruby example repository is a tiny Sinatra app with a browser form for sending test email.
Open Sinatra example