This is not supported by default. But you can achieve this functionality by using the action_mailer_callbacks plugin. Essentially this plugin allows you to add before
and after
filters for the deliver
method.
class FooMailer < ActionMailer::Base
before_deliver do |mail|
mail.from = "[email protected]"
end
end
Reference:
1) Article discussing the plugin.
OR
You can monkey patch the from
method of ActionMailer::Base
.
Add the code below to your config\initializers\mail.rb
class ActionMailer::Base
alias_method_chain :from, :default
def from_with_default(input=nil)
return from_without_default(input) || "[email protected]" if input.nil?
from_without_default(input)
end
end