Send email from Ruby on Rails (Action Mailer) over SMTP

Rails Action Mailer SMTP configuration: config.action_mailer.smtp_settings with address, port, authentication and enable_starttls, credentials from Rails credentials or ENV, a mailer class and deliver_later. Plain Ruby net/smtp snippet included.

Install

shell
# Action Mailer ships with Rails — plain Ruby: gem "net-smtp"

Complete example

Ruby on Rails — STARTTLS on 587, credentials from the environment
# config/environments/production.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  address:              ENV.fetch("SMTP_HOST", "smtp.queensmtp.com"),
  port:                 ENV.fetch("SMTP_PORT", 587).to_i,
  user_name:            ENV.fetch("SMTP_USER"),
  password:             ENV.fetch("SMTP_PASS"),
  authentication:       :plain,
  enable_starttls:      true,      # 587; for 465 use tls: true instead
  open_timeout:         20,
  read_timeout:         20,
}
config.action_mailer.default_url_options = { host: "yourdomain.com" }
config.action_mailer.raise_delivery_errors = true

# app/mailers/order_mailer.rb
class OrderMailer < ApplicationMailer
  default from: "Your App <hello@yourdomain.com>"

  def shipped(order)
    @order = order
    mail(to: order.customer_email, subject: "Your order has shipped")
  end
end

# anywhere
OrderMailer.shipped(order).deliver_later    # via Active Job; deliver_now to send inline

# plain Ruby (no Rails)
require "net/smtp"
msg = "From: hello@yourdomain.com\nTo: customer@example.com\nSubject: test\n\nSMTP works\n"
Net::SMTP.start("smtp.queensmtp.com", 587, "localhost", ENV["SMTP_USER"], ENV["SMTP_PASS"], :plain, tls: false, starttls: :always) do |smtp|
  smtp.send_message msg, "hello@yourdomain.com", "customer@example.com"
end

What to know

  • enable_starttls: true (Rails 7.1+; older: enable_starttls_auto) for 587; tls: true for 465 — not both.
  • deliver_later needs a job backend (Sidekiq, Solid Queue, GoodJob) in production.
  • Use the letter_opener gem in development and the Mailtrap sandbox host in staging.

Same code, different provider

Only the host, port and credentials change. The rules per provider are on the SMTP settings hub.

ProviderHostPortUsernamePasswordNote
QueenSMTP smtp.queensmtp.com587 (STARTTLS) / 465 (SSL) / 2525SMTP username from the dashboardSMTP password$5/year + $0.10 per 1,000; 100 free/day
Gmail smtp.gmail.com587 / 465you@gmail.comApp Password500/day, From must be the account
Amazon SES email-smtp.<region>.amazonaws.com587 / 465 / 2587SES SMTP usernameSES SMTP passwordsandbox 200/day until approved
Office 365 smtp.office365.com587user@yourdomain.commailbox passwordSMTP AUTH must be enabled; 30/min
SendGrid smtp.sendgrid.net587 / 465 / 2525apikeyAPI keyno free plan since 2025

Credentials for the example above

Create a free account, verify your sending domain (SPF + DKIM shown in the dashboard), add an SMTP credential, and paste it into the code. 100 emails a day free; $5/year plus $0.10 per 1,000 after that. Prefer HTTPS? The same account has a REST email API.

Get SMTP credentials Test your settings first

Other languages and frameworks

Examples tested 2026-08-30. If a library changed its API, tell us.

Ruby on Rails SMTP — questions

The SMTP credentials are wrong for that host. Gmail needs an App Password; relays need the credential from the dashboard, not the login password.