Generated by GPT-5-mini| Action Mailer | |
|---|---|
| Name | Action Mailer |
| Developer | Ruby on Rails core team |
| Released | 2005 |
| Programming language | Ruby |
| Platform | Cross-platform |
| License | MIT |
Action Mailer is a component of the Ruby on Rails web application framework that provides a framework for designing, testing, and delivering email services in web applications. It integrates with Active Record, Active Job, and the Rails routing system to generate multipart messages, templates, and delivery mechanisms suitable for transactional email, notifications, and bulk messaging. Action Mailer is used across projects that employ Ruby, JRuby, TruffleRuby, and server stacks involving Phusion Passenger, Puma, or Unicorn.
Action Mailer was introduced as part of the suite of components created by the DHH-led Basecamp team and matured within the Ruby on Rails core maintained by contributors from organizations like 37signals, GitHub, Shopify, Heroku, and Engine Yard. It follows the convention-over-configuration philosophy shared with Active Record, Action Controller, and Active View, and leverages template engines such as ERB, Haml, Slim, and Liquid. Action Mailer interacts with external providers including SendGrid, Mailgun, Amazon Simple Email Service, Postmark, SparkPost, SMTP servers hosted on Microsoft Exchange, Postfix, or Exim.
Action Mailer is organized around mailer classes, delivery methods, and message objects. Mailer classes inherit from Action Controller-style base classes found in the Rails stack, mirroring patterns in ActiveRecord::Base and controllers used in RESTful architecture applications. The main components include: - Mailer classes: Ruby classes that define mailer methods and rely on template lookup used by Rails engines and Rails applications. - Mail message objects: Instances resembling Mail objects that encapsulate headers, multipart bodies, and attachments, interoperating with the MIME standards adopted in Internet mail specifications. - Delivery methods: Adapters for protocols and services such as SMTP, SendGrid, Amazon SES, or custom HTTP APIs used by Heroku add-ons and AWS integrations. - Interceptors and observers: Hooks analogous to patterns used by ActiveSupport::Notifications and callback systems familiar from Active Record lifecycle events.
Action Mailer leverages gems and libraries like Mail::Message, Tilt, and integrates with background job systems such as Sidekiq, Resque, Delayed::Job, and Active Job adapters for asynchronous delivery.
Developers define mailer classes with named methods that compose messages using templates and helper modules shared with Action View and ViewComponent. Typical API surfaces include: - mail() method: Accepts options for :to, :from, :cc, :bcc, :subject, and :content_type; options mirror header fields defined in RFC 5322 for email. - attachments[]: Interface to add inline or regular attachments, interoperable with MIME multipart boundaries and content-transfer encodings used by IETF standards. - templates: Located under app/views/mailers and rendered with engines like ERB or Haml, allowing locale-aware templates informed by I18n configuration used in applications like Discourse, GitLab, and Redmine.
Action Mailer supports composing multipart emails (text/plain and text/html) and programmatic generation of headers consistent with migration patterns seen in GitHub projects. It exposes preview and test helpers integrated with Minitest, RSpec, and system testing stacks involving Capybara.
Configuration resides in environment files similar to Rails.configuration paradigms used by Rails Engines and deployment patterns used by Heroku and AWS Elastic Beanstalk. Delivery settings include: - smtp_settings: Host, port, authentication, and TLS settings compatible with Postfix, Sendmail, or cloud providers like Amazon SES and SendGrid. - delivery_method: Symbols like :smtp, :sendmail, :test, or :smtpapi for third-party providers integrated via gems maintained by Stripe, Twilio, and GitHub organizations. - credentials and secrets: Managed through Rails credentials, environment variables, or secrets managers used by HashiCorp Vault and AWS Secrets Manager.
Action Mailer supports secure transport via STARTTLS and SMTPS and can embed DKIM signatures, SPF records, and DMARC policies configured in DNS hosts such as Cloudflare or Amazon Route 53 to improve deliverability for applications like Shopify stores or Spree deployments.
Action Mailer integrates with Rails test frameworks and preview facilities. Features include: - Test delivery method: Captures emails in a deliveries array for assertions in Minitest or RSpec suites used in projects like RefineryCMS and AlchemyCMS. - Mailer previews: Routes under test environments that render templates in browsers, inspired by conventions used by Rails::Railtie and inspection tools used by Pry and Byebug. - Integration with CI/CD: Works with continuous integration services such as Travis CI, CircleCI, GitHub Actions, and Jenkins for regression testing and acceptance testing workflows.
Action Mailer is widely adopted in open-source and commercial Rails applications. Notable projects using Action Mailer patterns include Basecamp products, GitHub, Shopify, Discourse, Spree, RefineryCMS, Devise for authentication notifications, and Redmine for issue notifications. It is also used in integrations with SendGrid, Mailgun, Amazon SES, Postmark, and enterprise mail systems like Microsoft Exchange and G Suite (now part of Google Workspace). Action Mailer examples appear in community resources such as RailsGuides, blog posts from Thoughtbot, and tutorials authored by contributors active in the Ruby community.