sajad torkamani

As you prepare to deploy a Rails app, you’ll probably want to do a couple of things.

Configure Action Mailer

Set default URL options

I prefer to set a HOST environment variable and reference that instead of hardcoding the value. So, something like this:

config.action_mailer.default_url_options = { host: ENV.fetch('HOST') }

Only use the domain name for HOST (i.e., instead of

Set SMTP options

Assuming you’re using SMTP, set the correct configuration options. Refer to this post if using Gmail SMTP.

config.action_mailer.smtp_setting = { # ... }

Configure default sender email

You’ll also want to set an appropriate default sender email in your base ApplicationMailer class (app/mailers/application_mailer.rb). What follows is my preferred approach:

# frozen_string_literal: true

class ApplicationMailer < ActionMailer::Base
  default from: Rails.application.config.default_sender_email
  layout 'mailer'


config.default_sender_email = ENV.fetch('DEFAULT_SENDER_EMAIL')
config/environments/development.rb :
  config.default_sender_email = ENV.fetch(
  config.default_sender_email = ENV.fetch(

You’ll want document the need to set these environment variables in your README. Something like this:

### Local setup

### Deployment

### Set environment variables

| Name                   | Description                                                  |
| `HOST`                 | Domain where app is hosted.                                  |
| `DEFAULT_SENDER_EMAIL` | The email to be used as the sender for any outgoing emails.  |

Configure a queuing back-end

If you’re using ActiveJob, you’ll want to setup a queuing-backend like Sidekiq or Rescue.

Configure error monitoring service

You’ll want to set up a tool like Sentry so that you’re immediately informed if there’s a runtime error (front-end or back-end). You should be able to set up email or Slack notifications with most error monitoring services.

Configure job execution

Make sure to configure scheduled execution of any jobs. If using Heroku, consider using Heroku Scheduler. If deploying on own server, Cron should do the job.

Configure scheduled back ups

If you’re not using a managed database solution like AWS RDS, you’ll want to setup regular back ups of your database.

If you’re using the local driver for ActiveStorage, you’ll also want to configure regular backups of user files.

Other little things

  • Ensure you’re not exposing any sensitive credentials in Git. Store them in using Rails’s credentials feature.
  • Add favicon
  • Add analytics
Tagged: Rails