Sign inGet Started

Ruby SDK

Send email with Cuba

Use Parcel Wing from a compact Cuba route with JSON request parsing and structured errors.

Install the SDK

The official Ruby SDK is published as parcelwing.

Terminal

gem install parcelwing

Send from a route

Create the client once during boot and use Cuba's routing blocks to send trusted server-side email.

app.rb

require "cuba"
require "json"
require "parcelwing"
 
parcelwing = ParcelWing::Client.new(api_key: ENV.fetch("PARCELWING_API_KEY"))
 
Cuba.define do
on post, "send-welcome" do
payload = JSON.parse(req.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" }
)
 
res["content-type"] = "application/json"
res.write({ id: emails.first.fetch("id") }.to_json)
rescue ParcelWing::Error => error
res.status = error.status || 500
res["content-type"] = "application/json"
res.write({ error: error.code, request_id: error.request_id }.to_json)
end
 
on default do
res.status = 404
res.write "Not found"
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.