Given a Mailer
instance in Rails 3, is there a way to override the delivery_method
on it?
I want to push certain emails out through a high-priority transport, and others use a busier, low-priority method.
I can adjust the config at runtime and change it back again, but this is fraught with potential side-effects.
Action Mailer allows you to send emails from your application using mailer classes and views. Mailers work very similarly to controllers. They inherit from ActionMailer::Base and live in app/mailers , and they have associated views that appear in app/views .
rb, production. rb, etc...) Generates information on the mailing run if available.
Action Mailer allows you to send emails from your application using a mailer model and views. So, in Rails, emails are used by creating mailers that inherit from ActionMailer::Base and live in app/mailers. Those mailers have associated views that appear alongside controller views in app/views.
It turns out that doing this affects just this specific Mailer, without changing ActionMailer::Base
globally.
class SomeMailer < ActionMailer::Base
self.delivery_method = :high_priority
def some_email(params)
end
end
You can also do this (warning: will affect all instances of AnotherMailer
), if you have the instance up-front:
mail = AnotherMailer.whatever_email
mail.delivery_handler.delivery_method = :something_else
These don't seem to be documented, but work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With