Ruby SDK
Send email with Rack
Use Parcel Wing from a minimal Rack endpoint or any Rack-compatible Ruby application.
Install the SDK
The official Ruby SDK is published as parcelwing.
Terminal
gem install parcelwing
Rack endpoint
A Rack app returns a status, headers, and body. Keep the Parcel Wing client in server code and run it through rackup.
config.ru
# config.rurequire "json"require "rack"require "rack/request"require "parcelwing"parcelwing = ParcelWing::Client.new(api_key: ENV.fetch("PARCELWING_API_KEY"))app = lambda do |env|request = Rack::Request.new(env)unless request.post? && request.path == "/send-welcome"return [404, { "content-type" => "application/json" }, [{ error: "Not found" }.to_json]]endpayload = JSON.parse(request.body.read)emails = parcelwing.emails.send(from: ENV.fetch("PARCELWING_FROM_EMAIL"),to: payload.fetch("email"),template_alias: "welcome",template_params: { first_name: payload["first_name"] || "friend" })[200, { "content-type" => "application/json" }, [{ id: emails.first.fetch("id") }.to_json]]rescue ParcelWing::Error => error[error.status || 500, { "content-type" => "application/json" }, [{ error: error.code, request_id: error.request_id }.to_json]]endrun app
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.