Ruby on Rails

Action Mailer talks to a sandbox with one smtp_settings block per environment.

Prerequisites

  • Rails 6 or later

1Configure Action Mailer

config/environments/development.rb
# config/environments/development.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.smtp_settings = {
  address: 'smtp.mailclutch.com',
  port: 587,
  user_name: 'mc_0000000000000000',
  password: 'pw_0000000000000000',
  authentication: :plain,
  enable_starttls_auto: true
}

raise_delivery_errors is worth turning on here: without it a refused connection is swallowed and the sandbox simply stays empty.

2Send a test message

From rails console:

ActionMailer::Base.mail(
  from: 'staging@example.com',
  to: 'anyone@example.com',
  subject: 'Sandbox check',
  body: 'Hello from Rails.'
).deliver_now

Watch it land

Open the sandbox and the message is there — rendered HTML, plain text, raw source, attachments, and the SPF, DKIM and DMARC verdicts. It updates live, so you can leave it open next to your terminal.

Nothing is ever delivered onward, whatever address you send to; claim the sandbox with an account and it stays.

Awaiting your email

Send from any address; it stops here rather than going onward. The sandbox keeps what it catches for 24 hours.

Go further

  • deliver_later and Active Job

    deliver_later hands the mail to Active Job. Either run the queue backend, or use deliver_now while you are testing.

  • letter_opener and :file delivery

    A gem that sets delivery_method to :letter_opener or :file in development overrides the block above. Comment it out for the environment you are pointing here.

Official documentationRails — Action Mailer Basics (opens in a new tab)