I’m trying to setup a rails application so that I can choose between different mail delivery methods depending on whether some condition is true or not.
So, given two delivery methods:
ActionMailer::Base.add_delivery_method :foo
ActionMailer::Base.add_delivery_method :bar
I thought I’d be able to just create an email interceptor to do something like this:
class DeliveryMethodChooser
def self.delivering_email(message)
if some_condition
# code to use mail delivery method foo
else
# code to use mail delivery method bar
end
end
end
The problem though, is that I’m not sure how to actually set change what mail delivery method is used for a given message. Any ideas? Is it even possible to dynamically choose what delivery_method to use?
So, it turns out that you can actually pass a
Procas a default parameter toActionMailer.It’s therefore fully possible to do this:
I’m not sure I really sure I like this solution, but it works for the time being and it will only be for a relatively short amount of time.