1
votes

I want to create a Rails application where on first request the user is directed to a setup configuration wizard. In this wizard they will need to configure their email settings for ActionMailer to use, ie. SMTP server settings/credentials.

How can I programatically update the configuration entries for ActionMailer (I assume Application.rb will need to be updated)?

How can I make ActionMailer reload these updated configuration settings? I noticed that a lot of these settings are loaded on application start/initialization and I don't want to restart the Rails application for these changes to take effect.

1
It may not have been obvious, these SMTP settings given by the user should then used as the global SMTP settings across the application. The user is being allowed to set a site wide configuration.KrisG

1 Answers

7
votes

Just store settings into session and do this inside before filter for your AC:

class ApplicationController < ActionController::Base

    before_filter :set_mailer_settings

    private

      def set_mailer_settings

        ActionMailer::Base.smtp_settings = {
          :address  => session[:smtp_address],
          :port  => session[:smtp_port],
          :domain => session[:smtp_domain],
          :authentication => session[:smtp_authentication],
          :user_name => session[:smtp_user_name],
          :password => session[:smtp_password]
        }

      end

end