Prompt

How do I send emails from a Rails app?

Technology / Api platforms2 observationsLast seen Nov 20, 2026

Latest observation

Nov 20, 2026OpenAI APIWeb search: off

In Rails, the usual way to send email is with Action Mailer.

1) Generate a mailer

rails generate mailer UserMailer

This creates:

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

2) Define a mailer method

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

3) Create the email view

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

You can also add a text version:

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

4) Deliver the email

Call it from your app:

UserMailer.welcome_email(@user).deliver_now

Or send it asynchronously:

UserMailer.welcome_email(@user).deliver_later

5) Configure SMTP

In production, you’ll usually configure a mail provider like SendGrid, Mailgun, Amazon SES, or Postmark.

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

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  address: "smtp.sendgrid.net",
  port: 587,
  domain: "yourdomain.com",
  user_name: Rails.application.credentials.dig(:sendgrid, :username),
  password: Rails.application.credentials.dig(:sendgrid, :password),
  authentication: :plain,
  enable_starttls_auto: true
}

Also set:

config.action_mailer.default_url_options = { host: "example.com", protocol: "https" }

6) Set default sender

In app/mailers/application_mailer.rb:

class ApplicationMailer < ActionMailer::Base
  default from: "no-reply@example.com"
  layout "mailer"
end

7) Use credentials for secrets

Store email provider creds securely:

bin/rails credentials:edit

Example:

sendgrid:
  username: apikey
  password: your-secret-key

8) Test locally

For development, you can use:

config.action_mailer.delivery_method = :letter_opener

Then add the gem:

gem "letter_opener"

This opens emails in your browser instead of sending them.


Common gotchas

  • Make sure default_url_options is set for links in emails.
  • Use deliver_later if you don’t want email sending to block requests.
  • In production, use a real email service instead of plain SMTP from your own server.

If you want, I can also show you:

  • a full example with Devise
  • how to send password reset emails
  • how to configure Action Mailer for production with a specific provider

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (2 observations 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 dotdotPR. 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.