mcpField
A
action-mailer-coder

action-mailer-coder

github.com/majesticlabs-devDevelopment5067 installsUpdated 7w ago
Repository

About action-mailer-coder

A skill that guides coding agents in designing and implementing Rails Action Mailer mailers, from background delivery and previews to attachments and RSpec tests.

Key features

  1. 01Group related emails and parameterize mailers
  2. 02Set inherited dynamic defaults
  3. 03Queue and schedule delivery
  4. 04Preview and localize emails
  5. 05Handle attachments and write RSpec tests

Use cases

  1. 01Build account notifications and comment replies
  2. 02Schedule welcome emails, digests, or invoices
  3. 03Add previews and tests for mail templates

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/majesticlabs-dev/majestic-marketplace --skill action-mailer-coder

After installing, type/action-mailer-coderin Claude Code to confirm it loaded.

Details

From the project README

Action Mailer Coder

Mailer Design Principles

Group Related Emails
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
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
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("[email protected]", @account.name)
  end
end

Background Delivery

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

# 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

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

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)

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-PatternProblemSolution
One mailer per emailHard to navigateGroup related emails
Skipping .with()Implicit dependenciesUse parameterized mailers
deliver_nowBlocks requestUse deliver_later
Missing previewsCan't visually testCreate 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

Comments

Markdown supported