From e76871b75f9f39cfe62308e3f6b894122b0232a9 Mon Sep 17 00:00:00 2001 From: Yuki Date: Tue, 21 Jul 2015 23:03:30 +0530 Subject: [PATCH] Make the mailer respect APP_CONFIG.host, add ENV switches for letter_opener, mailcatcher and sendmail --- config/environments/development.rb | 11 +++++++++-- config/environments/production.rb | 2 +- config/initializers/10_config.rb | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/config/environments/development.rb b/config/environments/development.rb index 1272287c..30738511 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -16,8 +16,15 @@ Rails.application.configure do # Action Mailer Setup # if you want to test sending mails locally, uncomment the line below and comment the :sendmail line # config.action_mailer.delivery_method = :letter_opener - config.action_mailer.delivery_method = :sendmail - config.action_mailer.default_url_options = { host: 'justask.local' } + if ENV["mailcatcher"] == "yes" + config.action_mailer.delivery_method = :smtp + config.action_mailer.smtp_settings = { :address => "localhost", :port => 1025 } + elsif ENV["letteropener"] == "yes" + config.action_mailer.delivery_method = :letter_opener + else + config.action_mailer.delivery_method = :sendmail + end + config.action_mailer.perform_deliveries = true # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false diff --git a/config/environments/production.rb b/config/environments/production.rb index 62f40aeb..1c5656b5 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -68,7 +68,7 @@ Rails.application.configure do config.active_support.deprecation = :notify config.action_mailer.delivery_method = :sendmail - config.action_mailer.default_url_options = { host: 'retrospring.net' } + # config.action_mailer.default_url_options = { host: 'retrospring.net' } config.action_mailer.perform_deliveries = true # Ignore bad email addresses and do not raise email delivery errors. # Set this to true and configure the email server for immediate delivery to raise delivery errors. diff --git a/config/initializers/10_config.rb b/config/initializers/10_config.rb index c82b28c4..609c6afb 100644 --- a/config/initializers/10_config.rb +++ b/config/initializers/10_config.rb @@ -1,2 +1,2 @@ APP_CONFIG = YAML.load_file(Rails.root.join('config', 'justask.yml')) - +Rails.application.config.action_mailer.default_url_options = { host: APP_CONFIG['hostname'] }