Last Updated on August 4, 2026 by ian
Rails has Action Mailer built in. It’s one of the most complete email systems in any framework. This guide shows you how to configure ConvertNow as your Action Mailer delivery method, create mailers, use ERB templates, and handle common production patterns.
Step 1: Configure Action Mailer
Add SMTP settings to config/environments/production.rb:
# config/environments/production.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'out.convertnow.co',
port: 465,
ssl: true, # implicit SSL on port 465
user_name: ENV['MAIL_USERNAME'],
password: ENV['CONVERTNOW_API_KEY'],
authentication: :plain,
enable_starttls_auto: false, # not needed with implicit SSL
}
config.action_mailer.default_url_options = { host: 'myapp.com' }
Set your environment variables:
[email protected]
CONVERTNOW_API_KEY=cn_live_YOUR_KEY
Step 2: Generate a mailer
Use Rails’ generator to create your first mailer:
rails generate mailer UserMailer welcome_email password_reset
This creates app/mailers/user_mailer.rb and view templates in app/views/user_mailer/:
# app/mailers/user_mailer.rb
class UserMailer < ApplicationMailer
default from: '[email protected]'
def welcome_email
@user = params[:user]
mail(
to: @user.email,
subject: "Welcome to MyApp, #{@user.name}!"
)
end
def password_reset
@user = params[:user]
@token = params[:token]
mail(
to: @user.email,
subject: 'Reset your password'
)
end
end
Step 3: Create ERB email templates
Create app/views/user_mailer/welcome_email.html.erb:
<!DOCTYPE html>
<html>
<body>
<h1>Hi <%= @user.name %>!</h1>
<p>Your account is ready.</p>
<p><%= link_to 'Log in to your account', login_url %></p>
</body>
</html>
Create the plain-text version app/views/user_mailer/welcome_email.text.erb:
Hi <%= @user.name %>!
Your account is ready.
Log in here: <%= login_url %>
Step 4: Send the email from a controller
# app/controllers/users_controller.rb
class UsersController < ApplicationController
def create
@user = User.new(user_params)
if @user.save
# Send welcome email
UserMailer.with(user: @user).welcome_email.deliver_now
render json: { message: 'Account created' }, status: :created
else
render json: { errors: @user.errors }, status: :unprocessable_entity
end
end
end
Step 5: Queue emails with Active Job
deliver_now blocks the request thread. Use deliver_later in production so emails are processed in the background:
# In your controller or model callback:
UserMailer.with(user: @user).welcome_email.deliver_later
# With a delay:
UserMailer.with(user: @user).welcome_email.deliver_later(wait: 5.minutes)
# At a specific time:
UserMailer.with(user: @user).welcome_email.deliver_later(wait_until: Date.tomorrow.noon)
Configure Active Job to use Sidekiq in production (recommended):
# config/application.rb
config.active_job.queue_adapter = :sidekiq
Step 6: Send with attachments
def invoice_email
@user = params[:user]
@invoice = params[:invoice]
attachments['invoice.pdf'] = {
mime_type: 'application/pdf',
content: File.read(Rails.root.join('storage', 'invoices', @invoice.filename))
}
mail(
to: @user.email,
subject: "Your invoice ##{@invoice.number}"
)
end
Step 7: Send to multiple recipients with CC and BCC
def team_notification
@team = params[:team]
mail(
to: @team.members.map(&:email),
cc: @team.manager.email,
bcc: '[email protected]',
subject: 'Team update'
)
end
Testing mailers in development
In development, use the :test delivery method to capture emails without sending:
# config/environments/development.rb
config.action_mailer.delivery_method = :test
# Emails are available in ActionMailer::Base.deliveries array
ActionMailer::Base.deliveries.last
Or use Letter Opener gem to open emails in a browser automatically:
# Gemfile
gem 'letter_opener', group: :development
# config/environments/development.rb
config.action_mailer.delivery_method = :letter_opener
Start sending for free — convertnow.co — no credit card required

