Ruby on Rails introduces Action Mailbox in version 6.0
Using ActionMailbox, you can easily configure rules for routing incoming emails (examples from the documentation):
# app/mailboxes/application_mailbox.rb class ApplicationMailbox < ActionMailbox::Base routing /^ save@ /i => :forwards routing /@replies\./i => :replies end
And how to handle specific messages in the mailbox:
# app/mailboxes/forwards_mailbox.rb class ForwardsMailbox < ApplicationMailbox # Callbacks specify prerequisites to processing before_processing :require_forward def process if forwarder.buckets.one? record_forward else stage_forward_and_request_more_details end end private def require_forward unless message.forward? # Use Action Mailers to bounce incoming emails back to sender – this halts processing bounce_with Forwards::BounceMailer.missing_forward( inbound_email, forwarder: forwarder ) end end def forwarder @forwarder ||= Person.where(email_address: mail.from) end def record_forward forwarder.buckets.first.record \ Forward.new forwarder: forwarder, subject: message.subject, content: mail.content end def stage_forward_and_request_more_details Forwards::RoutingMailer.choose_project(mail).deliver_now end end
Find the documentation for configuring Action Mailbox and some examples in the Rails Guides .
source share