KrisG
KrisG

Reputation: 1091

Rails allow user to configure ActionMailer at runtime

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.

Upvotes: 1

Views: 1208

Answers (1)

ABrukish
ABrukish

Reputation: 1452

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

Upvotes: 7

Related Questions