Sign inGet Started

Ruby SDK

Send email with Padrino

Use Parcel Wing from Padrino helpers and controllers in a Sinatra-based Ruby app.

Install the SDK

The official Ruby SDK is published as parcelwing.

Terminal

gem install parcelwing

Create a helper

Register a small helper so controllers can reuse one Parcel Wing client.

app/helpers/parcelwing_helper.rb

# app/helpers/parcelwing_helper.rb
Acme::App.helpers do
def parcelwing
@parcelwing ||= ParcelWing::Client.new(
api_key: ENV.fetch("PARCELWING_API_KEY")
)
end
end

Send from a controller

Validate params, call a template, and translate Parcel Wing errors into JSON responses.

app/controllers/welcome_emails.rb

# app/controllers/welcome_emails.rb
Acme::App.controllers :welcome_emails do
post :create, map: "/send-welcome" do
content_type :json
 
emails = parcelwing.emails.send(
from: ENV.fetch("PARCELWING_FROM_EMAIL"),
to: params.fetch("email"),
template_alias: "welcome",
template_params: { first_name: params["first_name"].presence || "friend" }
)
 
{ 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

Production notes

  • Keep PARCELWING_API_KEY in server-side environment variables.
  • Use saved templates for onboarding, invites, receipts, and account notifications.
  • Log request_id from ParcelWing::Error for support and debugging.