Skip to main content

Ruby SDK

The jetemail gem is the official Ruby SDK for JetEmail transactional email (MIT license, Ruby 3.0+). Create a transactional API key in the dashboard: OutboundKeys → Add API key. Use that key with the SDK.

Installation

gem install jetemail
Or add to your Gemfile:
gem "jetemail"
Gem on RubyGems: jetemail.

Quick start

require "jetemail"

client = JetEmail::Client.new("your-transactional-api-key")

result = client.email.send(
  from: "Your App <[email protected]>",
  to: "[email protected]",
  subject: "Welcome!",
  html: "<h1>Welcome!</h1>"
)

puts result["id"]
Use a from address on a verified domain (see Getting started).

Constructor

# API key string
client = JetEmail::Client.new("your-transactional-api-key")

# Or with options
client = JetEmail::Client.new(
  api_key: "your-transactional-api-key",
  base_url: "https://api.jetemail.com" # optional
)

client.email.send(**options)

Send a single email.
FieldRequiredDescription
fromSender, e.g. "Name <[email protected]>"
toRecipient(s), string or array (max 50)
subjectSubject line
html*HTML body (need html and/or text)
text*Plain text (need html and/or text)
cc, bcc, reply_toRecipients (max 50 each)
headersCustom headers hash
attachmentsAttachments (max 40MB total)
Response shape: { "id" => String, "response" => String }.

client.batch.send(emails)

Send up to 100 emails in one request. Returns summary (total, successful, failed) and results per message.
result = client.batch.send([
  {
    from: "[email protected]",
    to: "[email protected]",
    subject: "Hello Alice",
    html: "<p>Hi Alice!</p>"
  },
  {
    from: "[email protected]",
    to: "[email protected]",
    subject: "Hello Bob",
    html: "<p>Hi Bob!</p>"
  }
])

Attachments

result = client.email.send(
  from: "[email protected]",
  to: "[email protected]",
  subject: "Invoice",
  html: "<p>Please find your invoice attached.</p>",
  attachments: [
    JetEmail::Attachment.from_path("/path/to/invoice.pdf"),
    JetEmail::Attachment.from_content("Hello World", "hello.txt")
  ]
)

Error handling

begin
  client.email.send(...)
rescue JetEmail::JetEmailError => e
  puts e.status_code
  puts e.message
  puts e.response
end
Common status codes: 400 invalid request, 401 bad/missing API key, 500 server error.
For additional examples and the full option list, see the RubyGems page. REST details: API reference.