Action Mailer
Action Mailer is a built-in framework in Ruby on Rails used to send emails directly from applications.
Table of Contents
What is Action Mailer in Ruby on Rails?
Action Mailer is a built-in framework in Ruby on Rails that makes it easy to send emails directly from your application. Just like Rails has controllers to handle web requests, Action Mailer acts like a “controller” for emails. It allows developers to create, format, and deliver emails without needing a separate email-sending tool.
Why is Action Mailer Useful?
Almost every modern web application needs email functionality, whether it’s sending a welcome message when a user signs up, resetting a forgotten password, or sending out order confirmations. Instead of writing complicated code to connect with email servers, Rails developers can use Action Mailer, which provides a ready-made structure and integrates smoothly with the rest of the Rails app.
How Action Mailer Works?
-
· Mailer Classes: You create a mailer (similar to a controller) that defines methods for different types of emails.
-
· Views/Templates: Each email can have HTML and/or plain-text templates, so you can design them like mini web pages.
-
· Delivery: Action Mailer connects with email services (SMTP, Gmail, SendGrid, AWS SES, etc.) to actually send the emails.
For example, a simple mailer might look like this:

And the email template (HTML view) could include:

When you call UserMailer.welcome_email(@user).deliver_now, the email is sent to the user instantly.
Setting Up Action Mailer (Configuration)
Before you can send emails, you need to configure Action Mailer in your Rails app.
You can do this inside config/environments/development.rb (and similarly for production):

This tells Rails how to connect to your email provider (in this case, Gmail). You can replace the settings with credentials for other services like SendGrid, Mailgun, or AWS SES.
Where to Use Action Mailer?
-
· User sign-up confirmations
-
· Password reset links
-
· Order receipts & invoices
-
· Weekly newsletters or updates
-
· System alerts/notifications
In Summary
Action Mailer is a built-in framework in Ruby on Rails used to send emails directly from applications. It provides an easy way to create mailers, design email templates, and connect
with email services for tasks like sign-ups, password resets, or order receipts. Beginners can use it to add email functionality without complex setup.