Guide · Ruby
How to send email with Ruby on Rails
Configure Action Mailer to deliver through the Stack Emails SMTP relay, then use deliver_later as usual.
Last reviewed November 2026
1. Set up
You need a Stack Emails API key (create one free) and a verified sending domain.
Store the key in credentials (bin/rails credentials:edit) as stackemails_api_key, or in an environment variable.
2. Send your first email
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.stackemails.com",
port: 465,
user_name: "stackemails",
password: Rails.application.credentials.stackemails_api_key,
authentication: :plain,
tls: true,
}
config.action_mailer.default_url_options = { host: "acme.com" }
A successful request returns 202 with the message id, for example { "id": "msg_5b1f0c6c2a8e4e0f", "status": "queued" }. Errors return a JSON body with error.code and error.message (see errors).
Send a mailer
class UserMailer < ApplicationMailer
default from: "Acme <hello@mail.acme.com>"
def welcome(user)
@user = user
mail(to: user.email, subject: "Welcome to Acme")
end
end
UserMailer.welcome(user).deliver_later
tls: true uses implicit TLS on port 465. For port 587 use enable_starttls_auto: true instead.
Production checklist
- Keep the API key in an environment variable or secret manager, never in client-side code.
- Add an
Idempotency-Keyheader to retries so a timeout never sends twice (idempotency). - Subscribe to webhooks for bounces and complaints.
- Check your domain's SPF, DKIM and DMARC records.
- Start from a tested email template for password resets, receipts and invites.