<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/testing-mailers-in-rails-cerziazfs" -->

---
title: Testing mailers in Rails | daily.dev
description: A hands-on Rails testing tutorial walking through building and testing a 'share recipe by email' feature using Minitest and Action Mailer. Covers writing...
canonical: https://daily.dev/posts/testing-mailers-in-rails-cerziazfs
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Testing mailers in Rails | daily.dev
og:description: A hands-on Rails testing tutorial walking through building and testing a 'share recipe by email' feature using Minitest and Action Mailer. Covers writing...
og:url: https://daily.dev/posts/testing-mailers-in-rails-cerziazfs
og:image: https://api.daily.dev/og/posts/cErZIazfs.png
og:image:alt: Testing mailers in Rails
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Testing mailers in Rails

**[Ruby Flow](https://daily.dev/sources/rubyflow)** · 26 min read · 0 upvotes · 1 comments

## Summary

A hands-on Rails testing tutorial walking through building and testing a 'share recipe by email' feature using Minitest and Action Mailer. Covers writing mailer tests for guest and signed-in scenarios, integration tests for the full HTTP flow, a system smoke test, implementing RecipeMailer#share, wiring routes/controller/view with a native HTML dialog, adding mailer previews viewable at /rails/mailers, and configuring letter_opener to preview real outgoing emails in the browser during development. Also adds a mailer test for an existing PasswordsMailer#reset action using freeze_time for deterministic token assertions.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://minitestrails.com/guide/testing-mailers>

## Questions this post answers

### How do I test an Action Mailer email with Minitest in Rails?

Use ActionMailer::TestCase, build the mail object (e.g. RecipeMailer.share(recipe, recipient, sender)), wrap deliver_now in assert_emails 1, then assert on email.to, email.from, email.subject, and email.body.encoded for content checks. Including Rails.application.routes.url_helpers in the test class lets you assert path helpers like recipe_path appear in the body.

_Developers wiring up mailer test coverage can find more Rails testing patterns on daily.dev._

### What is the difference between Rails mailer previews and letter_opener for viewing emails?

Mailer previews build a mail object directly from a class under test/mailers/previews/ and render it at /rails/mailers without any real delivery or form submission, useful for checking design. letter_opener instead intercepts an email after it is actually sent from the app (via deliver_now or deliver_later) and opens it in a new browser tab, confirming the email actually left the app.

_Teams debugging email delivery flows can track Rails mailer tooling changes on daily.dev._

### How do I configure letter_opener to preview sent emails in Rails development?

Add gem "letter_opener" to the development group in the Gemfile, run bundle install, then set config.action_mailer.delivery_method = :letter_opener in config/environments/development.rb. After that, any email sent from the app opens in a new browser tab instead of going to a real mailbox.

_Rails developers setting up local email testing can follow tooling updates like this on daily.dev._

## Community discussion

Top comments from developers on daily.dev.

**@nark3d** · 0 upvotes

> Love that the previews and letter_opener get their own slot.  Most tutorials skip straight to mocking and leave you blind to what the email actually looks like.  One thing I'd push on: asserting the email body contains the recipe link is the cheap test, but the expensive one is asserting the link actually works when a guest clicks it.  If the test only checks the string is present, a broken route or a token that expires before rendering still goes green.  Behaviour over content, every time.

## Similar posts on daily.dev

- [Testing authentication in Rails](https://daily.dev/posts/testing-authentication-in-rails-myv1qpxbt) · Ruby Flow · 0 upvotes · 0 comments
- [How to Test User Registration with Minitest Rails](https://daily.dev/posts/how-to-test-user-registration-with-minitest-rails-kmrtpfv3e) · Ruby Flow · 0 upvotes · 0 comments
- [Testing background jobs in Rails](https://daily.dev/posts/testing-background-jobs-in-rails-3cnpzddwv) · Ruby Flow · 0 upvotes · 0 comments
- [Painfully Simple Test Case Mistakes That Are Easy to Fix - FastRuby.io](https://daily.dev/posts/painfully-simple-test-case-mistakes-that-are-easy-to-fix---fastruby-io-qjqh0s0e4) · RUBYLAND · 0 upvotes · 0 comments
- [Authorization testing in Rails](https://daily.dev/posts/authorization-testing-in-rails-wcdiqgboi) · Ruby Flow · 0 upvotes · 0 comments

---

Tags: [#testing](https://daily.dev/tags/testing), [#rails](https://daily.dev/tags/rails)

[View this post on daily.dev](https://daily.dev/posts/testing-mailers-in-rails-cerziazfs)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Testing mailers in Rails","url":"https://daily.dev/posts/testing-mailers-in-rails-cerziazfs","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/testing-mailers-in-rails-cerziazfs"},"datePublished":"2026-09-04T14:50:43.487Z","dateModified":"2026-09-04T15:34:56.503Z","description":"A hands-on Rails testing tutorial walking through building and testing a 'share recipe by email' feature using Minitest and Action Mailer. Covers writing...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/6fd21df1018fa1b84524d156ad6beb8f?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/6fd21df1018fa1b84524d156ad6beb8f?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Ruby Flow","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Ruby Flow","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/a21aaa8bcbbf448193a016895c90a0e1","url":"https://daily.dev/sources/rubyflow"},"commentCount":1,"discussionUrl":"https://daily.dev/posts/testing-mailers-in-rails-cerziazfs","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":1}],"keywords":"testing,rails","timeRequired":"PT26M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Ruby Flow","item":"https://daily.dev/sources/rubyflow"},{"@type":"ListItem","position":3,"name":"Testing mailers in Rails"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/testing-mailers-in-rails-cerziazfs","comment":[{"@type":"Comment","text":"Love that the previews and letter_opener get their own slot.  Most tutorials skip straight to mocking and leave you blind to what the email actually looks like.  One thing I’d push on: asserting the email body contains the recipe link is the cheap test, but the expensive one is asserting the link actually works when a guest clicks it.  If the test only checks the string is present, a broken route or a token that expires before rendering still goes green.  Behaviour over content, every time.","datePublished":"2026-09-16T07:26:13.884Z","url":"https://daily.dev/posts/cErZIazfs#c-EIdq7TMRC","author":{"@type":"Person","name":"Adam","url":"https://daily.dev/nark3d","image":"https://avatars.githubusercontent.com/u/2162621?v=4"}}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/testing-mailers-in-rails-cerziazfs#faq","mainEntity":[{"@type":"Question","name":"How do I test an Action Mailer email with Minitest in Rails?","acceptedAnswer":{"@type":"Answer","text":"Use ActionMailer::TestCase, build the mail object (e.g. RecipeMailer.share(recipe, recipient, sender)), wrap deliver_now in assert_emails 1, then assert on email.to, email.from, email.subject, and email.body.encoded for content checks. Including Rails.application.routes.url_helpers in the test class lets you assert path helpers like recipe_path appear in the body. Developers wiring up mailer test coverage can find more Rails testing patterns on daily.dev."}},{"@type":"Question","name":"What is the difference between Rails mailer previews and letter_opener for viewing emails?","acceptedAnswer":{"@type":"Answer","text":"Mailer previews build a mail object directly from a class under test/mailers/previews/ and render it at /rails/mailers without any real delivery or form submission, useful for checking design. letter_opener instead intercepts an email after it is actually sent from the app (via deliver_now or deliver_later) and opens it in a new browser tab, confirming the email actually left the app. Teams debugging email delivery flows can track Rails mailer tooling changes on daily.dev."}},{"@type":"Question","name":"How do I configure letter_opener to preview sent emails in Rails development?","acceptedAnswer":{"@type":"Answer","text":"Add gem \"letter_opener\" to the development group in the Gemfile, run bundle install, then set config.action_mailer.delivery_method = :letter_opener in config/environments/development.rb. After that, any email sent from the app opens in a new browser tab instead of going to a real mailbox. Rails developers setting up local email testing can follow tooling updates like this on daily.dev."}}]}
```

