How to send emails with Ruby on Rails

Send emails from Ruby/Rails by calling the Publiq REST API with the `net/http` stdlib.

There is no official SDK — call the Publiq REST API with your language HTTP client, from the server, with the API key in the Authorization header.

require 'net/http'
require 'json'

def send_welcome(user)
  uri = URI('https://api.publiq.digital/v1/emails')
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true

  req = Net::HTTP::Post.new(uri)
  req['Authorization'] = "Bearer #{ENV['PUBLIQ_API_KEY']}"
  req['Content-Type'] = 'application/json'
  req.body = {
    from: 'you@yourdomain.com',
    to: user.email,
    templateKey: 'welcome-email',
    variables: { first_name: user.name }
  }.to_json

  JSON.parse(http.request(req).body)
end

Best practices

  • Always call Publiq from the server — the API key goes in the Authorization header, never on the client.
  • On 429/5xx, retry with exponential backoff (respect Retry-After).
  • Prefer templateKey over inline HTML to keep content versioned.
  • Handle errors via the response error.code field — see Errors.
  • Send from a verified domain — see Domains.

See also

How to send emails with Ruby on Rails — Publiq Docs