2

I've built a custom email delivery method for my Rails 4 app:

module CustomDeliverer
  class DeliveryMethod

    def initialize(options = {})
    end

    def deliver!(mail)
      # method body hidden/not relevant for this question
    end
  end
end

I've also followed the example in the letter opener gem to register a custom delivery method:

module CustomDeliverer
  class Railtie < Rails::Railtie
    initializer "custom_deliverer.add_delivery_method" do
      ActiveSupport.on_load :action_mailer do
        ActionMailer::Base.add_delivery_method :custom_deliverer, CustomDeliverer::DeliveryMethod
      end
    end
  end
end

I've set my config file to use this deliverer:

config.action_mailer.delivery_method = :custom_deliverer

When I try to deliver a mail in my app, I get the error:

Invalid delivery method :custom_deliverer

However, when I set the config file to use the deliverer directly:

config.action_mailer.delivery_method = CustomDeliverer::DeliveryMethod

it works correctly, but anytime that code changes in the application (when developing locally), I get the error:

CustomDeliverer::DeliveryMethod has been removed from the module tree but is still active!

Where am I supposed to register or require CustomDeliverer::Railtie in my rails app so that I can set the delivery method via a symbol?

Oved D
  • 7,132
  • 10
  • 47
  • 69

1 Answers1

2

Figured it out:

Instead of using a Railtie, which is just meant for gems, added an initializer, config/initializers/add_custom_delivery_method.rb:

ActiveSupport.on_load :action_mailer do
  ActionMailer::Base.add_delivery_method :custom_deliverer, CustomDeliverer::DeliveryMethod
end
Oved D
  • 7,132
  • 10
  • 47
  • 69