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.rbAcme::App.helpers dodef parcelwing@parcelwing ||= ParcelWing::Client.new(api_key: ENV.fetch("PARCELWING_API_KEY"))endend
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.rbAcme::App.controllers :welcome_emails dopost :create, map: "/send-welcome" docontent_type :jsonemails = 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_jsonrescue ParcelWing::Error => errorstatus error.status || 500{ error: error.code, request_id: error.request_id }.to_jsonendend
Production notes
- Keep
PARCELWING_API_KEYin server-side environment variables. - Use saved templates for onboarding, invites, receipts, and account notifications.
- Log
request_idfromParcelWing::Errorfor support and debugging.