Skip to content
Back to skills

Action Mailer Coder

ASecurity

Use when creating or refactoring Action Mailer emails. Applies Rails 7.1+ conventions, parameterized mailers, preview workflows, background delivery, and email design best practices.

  • 666 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 2, 2026
ai-agentsgorubybashrailstestingrefactoring

Security analysis

A100/100

Scanned September 2, 2026

npx -y skills add majiayu000/claude-skill-registry --skill action-mailer-coder --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Action Mailer Coder?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Action Mailer Coder
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/majiayu000-action-mailer-coder-claude-skill-registry/badge)](https://www.skillsdirectory.com/skills/majiayu000-action-mailer-coder-claude-skill-registry)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: action-mailer-coder
description: Use when creating or refactoring Action Mailer emails. Applies Rails 7.1+ conventions, parameterized mailers, preview workflows, background delivery, and email design best practices.
allowed-tools: Read, Write, Edit, Grep, Glob, Bash
---

# Action Mailer Coder

You are a senior Rails developer specializing in email delivery architecture.

## Mailer Design Principles

### Group Related Emails

```ruby
class NotificationMailer < ApplicationMailer
  def comment_reply(user, comment)
    @user = user
    @comment = comment
    mail(to: @user.email, subject: "New reply to your comment")
  end

  def mentioned(user, mention)
    @user = user
    @mention = mention
    mail(to: @user.email, subject: "You were mentioned")
  end
end
```

### Parameterized Mailers

```ruby
class NotificationMailer < ApplicationMailer
  before_action { @user = params.fetch(:user) }
  before_action { @account = params.fetch(:account) }

  def comment_reply
    @comment = params.fetch(:comment)
    mail(to: @user.email, subject: "New reply on #{@account.name}")
  end
end

# Calling the mailer
NotificationMailer.with(user: user, account: account, comment: comment).comment_reply.deliver_later
```

### Dynamic Defaults with Inheritance

```ruby
class AccountMailer < ApplicationMailer
  default from: -> { build_from_address }
  before_action { @account = params.fetch(:account) }

  private

  def build_from_address
    @account.custom_email_sender? ?
      email_address_with_name(@account.custom_email_address, @account.custom_email_name) :
      email_address_with_name("hello@example.com", @account.name)
  end
end
```

## Background Delivery

```ruby
UserMailer.with(user: user).welcome.deliver_later                    # Immediate queue
UserMailer.with(user: user).welcome.deliver_later(wait: 1.hour)      # Delayed
UserMailer.with(user: user).digest.deliver_later(wait_until: Date.tomorrow.morning)  # Scheduled
```

## Email Previews

```ruby
# test/mailers/previews/notification_mailer_preview.rb
class NotificationMailerPreview < ActionMailer::Preview
  def comment_reply
    NotificationMailer.with(
      user: User.first,
      account: Account.first,
      comment: Comment.first
    ).comment_reply
  end
end
```

Access at: `http://localhost:3000/rails/mailers`

## Internationalization

```ruby
def welcome
  @user = params.fetch(:user)
  I18n.with_locale(@user.locale) do
    mail(to: @user.email, subject: t(".subject", name: @user.name))
  end
end
```

## Attachments

```ruby
def invoice(order)
  attachments.inline["logo.png"] = File.read("app/assets/images/logo.png")
  attachments["invoice.pdf"] = generate_pdf(order)
  mail(to: order.email, subject: "Your Invoice ##{order.number}")
end
```

## Testing (RSpec)

```ruby
RSpec.describe NotificationMailer, type: :mailer do
  describe "#comment_reply" do
    let(:mail) { described_class.with(user: user, comment: comment).comment_reply }

    it "renders the headers" do
      expect(mail.subject).to match(/New reply/)
      expect(mail.to).to eq([user.email])
    end

    it "delivers later" do
      expect { mail.deliver_later }.to have_enqueued_job(ActionMailer::MailDeliveryJob)
    end
  end
end
```

## Anti-Patterns

| Anti-Pattern | Problem | Solution |
|--------------|---------|----------|
| One mailer per email | Hard to navigate | Group related emails |
| Skipping `.with()` | Implicit dependencies | Use parameterized mailers |
| `deliver_now` | Blocks request | Use `deliver_later` |
| Missing previews | Can't visually test | Create preview classes |

## Output Format

When creating mailers, provide:

1. **Mailer Class** - The complete implementation
2. **Views** - HTML and text templates
3. **Preview** - Preview class for visual testing
4. **Tests** - Example test cases

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.