Skip to content

Commit

Permalink
ActionMailer.default_url_options[:host] is assigned from Settings. Th…
Browse files Browse the repository at this point in the history
…is prepares the code for cases where emails will be sent outside of a ActionController request. From this point on you will need to include 'mail_host' in your settings files.
  • Loading branch information
steveyken committed Nov 25, 2011
1 parent 5a7d2f2 commit 1587c51
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
1 change: 0 additions & 1 deletion app/controllers/application_controller.rb
Expand Up @@ -108,7 +108,6 @@ def field_group
#----------------------------------------------------------------------------
def set_context
Time.zone = ActiveSupport::TimeZone[session[:timezone_offset]] if session[:timezone_offset]
ActionMailer::Base.default_url_options[:host] = request.host_with_port
I18n.locale = Setting.locale if Setting.locale

# Check if the latest settings have been loaded. Display error message in English
Expand Down
2 changes: 0 additions & 2 deletions config/environments/development.rb
Expand Up @@ -27,8 +27,6 @@
File.delete(File.join(Rails.root, 'tmp', 'debug.txt'))
end

# ActionMailer needs to be loaded here so that we can set default_url_options in the controller.
ActionMailer::Base
end

ActiveSupport.on_load(:after_initialize) do
Expand Down
3 changes: 0 additions & 3 deletions config/environments/production.rb
Expand Up @@ -46,8 +46,5 @@

# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify

# ActionMailer needs to be loaded here so that we can set default_url_options in the controller.
ActionMailer::Base
end

3 changes: 0 additions & 3 deletions config/environments/test.rb
Expand Up @@ -32,9 +32,6 @@

# Print deprecation notices to the stderr
config.active_support.deprecation = :stderr

ActionMailer::Base
config.action_mailer.default_url_options = { :host => 'localhost' }
end

# Optionally load 'awesome_print' for debugging in development mode.
Expand Down
3 changes: 3 additions & 0 deletions config/initializers/fat_free_crm_action_mailer.rb
@@ -0,0 +1,3 @@
if Setting.table_exists? and !Setting.mail_host.nil?
Rails.application.config.action_mailer.default_url_options[:host] = Setting.mail_host
end
14 changes: 14 additions & 0 deletions config/settings.yml
Expand Up @@ -32,6 +32,20 @@
#
:base_url: ""

# Mail host
#------------------------------------------------------------------------------
# Default host used when action mailer generates urls.
#
# When sending email, you will need to set the host name so that the mailer can
# generate urls inside emails that point back to your site. Unlike controllers
# from Action Pack, the mailer instance doesn’t have any context about the
# incoming request, so you’ll need to provide all of the details needed to
# generate a URL.
#
# :mail_host: "http://www.example.com"
#
:mail_host: ""

# Locale.
#------------------------------------------------------------------------------
# Default locale is American English.
Expand Down

0 comments on commit 1587c51

Please sign in to comment.