From a7b8481c8f8675d13f47fa88bb6c941800ee11b1 Mon Sep 17 00:00:00 2001 From: Cyril Rohr Date: Tue, 8 Oct 2013 15:48:57 +0100 Subject: [PATCH] Allow to set SMTP settings via environment variable. --- config/environments/production.rb.sample | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/config/environments/production.rb.sample b/config/environments/production.rb.sample index c12b534dd2a..ef934d5e72c 100644 --- a/config/environments/production.rb.sample +++ b/config/environments/production.rb.sample @@ -40,8 +40,27 @@ Discourse::Application.configure do # :authentication => 'plain', # :enable_starttls_auto => true } - config.action_mailer.delivery_method = :sendmail - config.action_mailer.sendmail_settings = {arguments: '-i'} + if ENV.key?('SMTP_URL') + config.action_mailer.smtp_settings = begin + uri = URI.parse(ENV['SMTP_URL']) + params = { + :address => uri.host, + :port => uri.port, + :domain => (uri.path || "").split("/")[1], + :user_name => uri.user, + :password => uri.password, + :authentication => 'plain', + :enable_starttls_auto => true + } + CGI.parse(uri.query || "").each {|k,v| params[k.to_sym] = v.first} + params + rescue + raise "Invalid SMTP_URL" + end + else + config.action_mailer.delivery_method = :sendmail + config.action_mailer.sendmail_settings = {arguments: '-i'} + end # Send deprecation notices to registered listeners config.active_support.deprecation = :notify