Skip to content

Send Emails with Ruby on Rails

Learn how to send transactional emails using PostStack and Ruby on Rails.

1. Install the SDK

bash
# No external gems needed — uses the standard library

2. Initialize the client

ruby
require 'net/http'
require 'json'
require 'uri'

API_KEY = ENV['POSTSTACK_API_KEY']
BASE_URL = 'https://api.poststack.dev'

3. Send an email

ruby
require 'net/http'
require 'json'
require 'uri'

api_key = ENV['POSTSTACK_API_KEY']
uri = URI('https://api.poststack.dev/v1/emails')

http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

request = Net::HTTP::Post.new(uri)
request['Authorization'] = "Bearer #{api_key}"
request['Content-Type'] = 'application/json'
request.body = {
  from: 'hello@yourdomain.com',
  to: 'user@example.com',
  subject: 'Hello from Ruby!',
  html: '<h1>Welcome!</h1>'
}.to_json

response = http.request(request)
puts response.body

Notes

  • Uses the Ruby standard library — no gems required
  • For Rails, you can also configure PostStack as an SMTP transport in config/mail.php

Ready to send emails with Ruby on Rails?

Create a free account and get your API key in under a minute.