Prompt

How do I send emails from a Rails app?

Technology / Api platforms1 observationLast seen Sep 23, 2026

Latest observation

Sep 23, 2026OpenAI APIWeb search: off

In Rails, you typically send email with Action Mailer, which is built into Rails.

1. Create a mailer

Generate one with:

rails generate mailer UserMailer

This creates:

  • app/mailers/user_mailer.rb
  • app/views/user_mailer/
  • test files

2. Define an email method

Example:

# app/mailers/user_mailer.rb
class UserMailer < ApplicationMailer
  def welcome_email(user)
    @user = user
    mail(to: @user.email, subject: "Welcome to My App")
  end
end

3. Create the email view

Rails will look for a view matching the method name:

<!-- app/views/user_mailer/welcome_email.html.erb -->
<h1>Welcome, <%= @user.name %>!</h1>
<p>Thanks for signing up.</p>

You can also create a text version:

<!-- app/views/user_mailer/welcome_email.text.erb -->
Welcome, <%= @user.name %>!
Thanks for signing up.

4. Send the email

From a controller, job, or anywhere in your app:

UserMailer.welcome_email(@user).deliver_now

Or asynchronously:

UserMailer.welcome_email(@user).deliver_later

5. Configure delivery settings

You need to configure a mail delivery method in your environment files.

Example for SMTP in config/environments/production.rb:

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  address: "smtp.gmail.com",
  port: 587,
  user_name: ENV["SMTP_USERNAME"],
  password: ENV["SMTP_PASSWORD"],
  authentication: :login,
  enable_starttls_auto: true
}
config.action_mailer.default_url_options = { host: "yourdomain.com" }

For development, you might use a tool like letter_opener or mailcatcher to preview emails instead of sending real ones.

6. Set defaults in ApplicationMailer

# app/mailers/application_mailer.rb
class ApplicationMailer < ActionMailer::Base
  default from: "no-reply@yourdomain.com"
  layout "mailer"
end

Example: full flow

# app/models/user.rb
class User < ApplicationRecord
end
# app/mailers/user_mailer.rb
class UserMailer < ApplicationMailer
  def welcome_email(user)
    @user = user
    mail(to: @user.email, subject: "Welcome!")
  end
end
# app/controllers/users_controller.rb
class UsersController < ApplicationController
  def create
    @user = User.create!(user_params)
    UserMailer.welcome_email(@user).deliver_later
    redirect_to root_path, notice: "Account created!"
  end
end

If you want, I can also show you:

  • how to send emails with Devise
  • how to set up SMTP with Gmail/SendGrid
  • how to build HTML + text multipart emails
  • how to send emails from background jobs

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as Circuit. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.