Install the SDK
gem install groundmailOr add to your Gemfile:
gem "groundmail", "~> 0.8"Configure your API key
export GROUNDMAIL_API_KEY=gm_your_key_hereSend an email (API client)
require "groundmail"
tx = Groundmail::Client.new(ENV.fetch("GROUNDMAIL_API_KEY"))
result = tx.emails.send(
from: "ops@yourdomain.com",
to: "user@example.com",
subject: "Your receipt",
html: "<p>Thanks for your purchase.</p>"
)
puts result["id"], result["status"]Rails ActionMailer (recommended)
Full walkthrough: Groundmail with Rails.
With Rails present, the gem registers a delivery method automatically.
# config/environments/production.rb (or application.rb)
config.action_mailer.delivery_method = :groundmail
config.action_mailer.groundmail_settings = {
api_key: ENV.fetch("GROUNDMAIL_API_KEY")
# base_url: "https://api.groundmail.dev"
}Then send Mailables as usual:
UserMailer.welcome(user).deliver_laterWithout the Railtie (manual registration):
ActionMailer::Base.add_delivery_method :groundmail, Groundmail::DeliveryMethodTags, idempotency, and schedule
Set headers on the message:
mail(
to: user.email,
subject: "Welcome",
"X-Groundmail-Tag" => "campaign=welcome",
"X-Groundmail-Idempotency-Key" => "welcome-#{user.id}"
# "X-Groundmail-Scheduled-At" => "2030-01-01T00:00:00Z"
)X-Groundmail-Tag uses name=value. Custom non-reserved headers are forwarded to the API headers field.
Resources
The client includes thin wrappers for common API resources:
tx.emails— send, batch, list, cancel, resend, test webhooks, deliverability insightstx.domains— create, verify, apply DNS, update, deletetx.webhooks— CRUD for webhook endpointstx.templates— CRUD plus publishtx.suppressions— list, create, removetx.validate(email)andtx.validate_batch(emails)— check addresses before you accept them (validation);mailbox_check: truealso confirms the mailbox exists
See the API reference for request fields. The Ruby SDK accepts the same JSON shapes as the REST API.
Source
Package source lives in ruby/ in the public groundmail-sdks repository.