[Feature Proposal] [ActionMailer] Send/forward mail objects

Since working with ActionMailbox, we found ourselves needing to forward certain inbound emails that weren’t processed. Current workflow is somewhat hacky:

class ForwarderMailer < ::ApplicationMailer
  def forward(inbound_email)
    mail = inbound_email.mail

    mail.from = "app@example.com"
    mail.to = "operations@example.com"
    mail.subject = "FWD: #{mail.subject}"
    # Use ActionMailer delivery_method, instead of Mail.defaults
    self.class.wrap_delivery_behavior(mail, delivery_method)


The above method saves us from rebuilding a new mail object, reattaching any attachments and not modifying existing Mail.defaults as the application might have different default mechanism. This works, but I’m not happy about the commented line. Would be great to be able to do:

class ForwarderMailer < ::ApplicationMailer
  default from: "app@example.com", to: "operations@example.com"

  def forward_email(inbound_email)
    mail = inbound_email.mail

    forward(mail, subject: "FWD: #{mail.subject}")

This requires implementation of ActionMailer#forward(mail, headers = {}, &block), which would work as ActionMailer#mail(headers = {}, &block), but it would:

  • accept mail object;
  • overwrite any headers submitted;
  • use block as for mail (for different formats);
  • use default ActionMailer delivery method.

I’d be happy to implement this, but first I wanted to hear if anyone else had to deal with this.