views:

19

answers:

1

Right now i have set my all smtp setting in environment.rb file.

I have stored my all setting in database.

I want to bind smtp setting from my model.

How may i dynamically bind those settings from model ?

A: 
class UserMailer < ActionMailer::Base

   UserMailer.smtp_settings = {
      :tls            => Model.find_by_column_name("SMTP_TLS").column_name,
      :address        => Model.find_by_column_name("SMTP_ADDRESS").column_name,
      :port           => Model.find_by_column_name("SMTP_PORT").column_name,
      :domain         => Model.find_by_column_name("SMTP_DOMAIN").column_name
   }

  def mail_example(to_address,subject,options={})
    sender(to_address,subject,options)
  end

  def sender(to_address,subject,options)
    recipients to_address
    from Model.find_by_column_name("SMTP_FROM_ADDRESS").column_name
    subject subject
    sent_on Time.now
    body options
  end
end

I have create a common sender function. May be that will help.

krunal shah