rails/rails — pull request #7397 by asanghi (2012-08-20 13:31:47+00:00)
Title: Allow delivery method options to be set per mail instance

There is a common use case where mail settings are dynamic based on settings saved in database. For example, we could let companies provide us with their SMTP credentials which can be used to send email on their behalf. My particular use case dealt with creating a delivery method which sends SMSes based on company's credentials to company's users.

This PR allows the user to easily set delivery method settings from within the mail instance

````ruby
class MySmsMailer < ActionMailer::Base
def send_sms(company,telephone_number,message)
mail :to => telephone_number,
:body => message,
:delivery_method => :sms_sender,
:delivery_method_options => company.sms_credentials
end
end
````

The alternative to doing this would be rather ugly

````ruby
m = MySmsMailer.send_sms(company,number,message)
m.delivery_method.some_method_that_sets_options_on_sms_sender_instance(company.sms_credentials)
m.deliver
````

We could try to set delivery options by resetting them on classes but I dont imagine it would be threadsafe to do that!

/cc @josevalim @mikel