moving mail config into an initializer and a config/smtp.yml file

Albert Sun %!s(int64=11) %!d(string=hace) años
padre
commit
9874e2b41a

+ 1 - 9
config/environments/development.rb

@@ -39,13 +39,5 @@ Huginn::Application.configure do
39 39
   config.action_mailer.perform_deliveries = false # Enable when testing!
40 40
   config.action_mailer.raise_delivery_errors = true
41 41
   config.action_mailer.delivery_method = :smtp
42
-  config.action_mailer.smtp_settings = {
43
-      address: ENV['SMTP_SERVER'] || 'smtp.gmail.com',
44
-      port: ENV['SMTP_PORT'] || 587,
45
-      domain: ENV['SMTP_DOMAIN'],
46
-      authentication: ENV['SMTP_AUTHENTICATION'] || 'plain',
47
-      enable_starttls_auto: ENV['SMTP_ENABLE_STARTTLS_AUTO'] == 'true' ? true : false,
48
-      user_name: ENV['SMTP_USER_NAME'],
49
-      password: ENV['SMTP_PASSWORD']
50
-  }
42
+  # smtp_settings moved to config/initializers/action_mailer.rb
51 43
 end

+ 4 - 9
config/environments/production.rb

@@ -66,16 +66,11 @@ Huginn::Application.configure do
66 66
 
67 67
   config.action_mailer.default_url_options = { :host => ENV['DOMAIN'] }
68 68
   config.action_mailer.asset_host = ENV['DOMAIN']
69
+  if ENV['ASSET_HOST']
70
+    config.action_mailer.asset_host = ENV['ASSET_HOST']
71
+  end
69 72
   config.action_mailer.perform_deliveries = true
70 73
   config.action_mailer.raise_delivery_errors = true
71 74
   config.action_mailer.delivery_method = :smtp
72
-  config.action_mailer.smtp_settings = {
73
-      address: ENV['SMTP_SERVER'] || 'smtp.gmail.com',
74
-      port: ENV['SMTP_PORT'] || 587,
75
-      domain: ENV['SMTP_DOMAIN'],
76
-      authentication: ENV['SMTP_AUTHENTICATION'] || 'plain',
77
-      enable_starttls_auto: ENV['SMTP_ENABLE_STARTTLS_AUTO'] == 'true' ? true : false,
78
-      user_name: ENV['SMTP_USER_NAME'],
79
-      password: ENV['SMTP_PASSWORD']
80
-  }
75
+  # smtp_settings moved to config/initializers/action_mailer.rb
81 76
 end

+ 5 - 10
config/environments/staging.rb

@@ -66,16 +66,11 @@ Huginn::Application.configure do
66 66
 
67 67
   config.action_mailer.default_url_options = { :host => ENV['DOMAIN'] }
68 68
   config.action_mailer.asset_host = ENV['DOMAIN']
69
+  if ENV['ASSET_HOST']
70
+    config.action_mailer.asset_host = ENV['ASSET_HOST']
71
+  end
69 72
   config.action_mailer.perform_deliveries = true
70 73
   config.action_mailer.raise_delivery_errors = true
71 74
   config.action_mailer.delivery_method = :smtp
72
-  config.action_mailer.smtp_settings = {
73
-      address: ENV['SMTP_SERVER'] || 'smtp.gmail.com',
74
-      port: ENV['SMTP_PORT'] || 587,
75
-      domain: ENV['SMTP_DOMAIN'],
76
-      authentication: ENV['SMTP_AUTHENTICATION'] || 'plain',
77
-      enable_starttls_auto: ENV['SMTP_ENABLE_STARTTLS_AUTO'] == 'true' ? true : false,
78
-      user_name: ENV['SMTP_USER_NAME'],
79
-      password: ENV['SMTP_PASSWORD']
80
-  }
81
-end
75
+  # smtp_settings moved to config/initializers/action_mailer.rb
76
+end

+ 16 - 0
config/initializers/action_mailer.rb

@@ -0,0 +1,16 @@
1
+# Read smtp config out of a config/smtp.yml file
2
+
3
+smtp_config = YAML::load(ERB.new(File.read(Rails.root.join('config', 'smtp.yml'))).result)
4
+if smtp_config.keys.include? Rails.env
5
+  Huginn::Application.config.action_mailer.smtp_settings = smtp_config[Rails.env].symbolize_keys
6
+end
7
+
8
+# Huginn::Application.config.action_mailer.smtp_settings = {
9
+#   address: ENV['SMTP_SERVER'] || 'smtp.gmail.com',
10
+#   port: ENV['SMTP_PORT'] || 587,
11
+#   domain: ENV['SMTP_DOMAIN'],
12
+#   authentication: ENV['SMTP_AUTHENTICATION'] || 'plain',
13
+#   enable_starttls_auto: ENV['SMTP_ENABLE_STARTTLS_AUTO'] == 'true' ? true : false,
14
+#   user_name: ENV['SMTP_USER_NAME'],
15
+#   password: ENV['SMTP_PASSWORD']
16
+# }

+ 26 - 0
config/smtp.yml

@@ -0,0 +1,26 @@
1
+development:
2
+  address: <%= ENV['SMTP_SERVER'] || "smtp.gmail.com" %>
3
+  port: <%= ENV['SMTP_PORT'] || 587 %>
4
+  domain: <%= ENV['SMTP_DOMAIN'] %>
5
+  authentication: <%= ENV['SMTP_AUTHENTICATION'] || "plain" %>
6
+  enable_starttls_auto: <%= ENV['SMTP_ENABLE_STARTTLS_AUTO'] == 'true' ? true : false %>
7
+  user_name: <%= ENV['SMTP_USER_NAME'] || "" %>
8
+  password: <%= ENV['SMTP_PASSWORD'] || "" %>
9
+
10
+staging:
11
+  address: <%= ENV['SMTP_SERVER'] || "smtp.gmail.com" %>
12
+  port: <%= ENV['SMTP_PORT'] || 587 %>
13
+  domain: <%= ENV['SMTP_DOMAIN'] %>
14
+  authentication: <%= ENV['SMTP_AUTHENTICATION'] || "plain" %>
15
+  enable_starttls_auto: <%= ENV['SMTP_ENABLE_STARTTLS_AUTO'] == 'true' ? true : false %>
16
+  user_name: <%= ENV['SMTP_USER_NAME'] || "" %>
17
+  password: <%= ENV['SMTP_PASSWORD'] || "" %>
18
+
19
+production:
20
+  address: <%= ENV['SMTP_SERVER'] || "smtp.gmail.com" %>
21
+  port: <%= ENV['SMTP_PORT'] || 587 %>
22
+  domain: <%= ENV['SMTP_DOMAIN'] %>
23
+  authentication: <%= ENV['SMTP_AUTHENTICATION'] || "plain" %>
24
+  enable_starttls_auto: <%= ENV['SMTP_ENABLE_STARTTLS_AUTO'] == 'true' ? true : false %>
25
+  user_name: <%= ENV['SMTP_USER_NAME'] || "" %>
26
+  password: <%= ENV['SMTP_PASSWORD'] || "" %>