From fc42dd2cef3f1e43af19f6455011cdd5d298aef5 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Fri, 4 Jul 2008 18:55:45 +0000 Subject: [PATCH] Email delivery configuration moved to an unversioned YAML file (config/email.yml, see the sample file) (#1412). Email delivery is disabled. It's automatically turned on when configuration is found. git-svn-id: http://redmine.rubyforge.org/svn/trunk@1625 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/settings_controller.rb | 1 + app/views/settings/_notifications.rhtml | 6 ++++++ config/email.yml.example | 21 +++++++++++++++++++++ config/environment.rb | 24 ++++-------------------- config/environments/test.rb | 1 + config/environments/test_pgsql.rb | 3 ++- config/environments/test_sqlite3.rb | 3 ++- config/initializers/40-email.rb | 17 +++++++++++++++++ doc/INSTALL | 10 +++++----- doc/UPGRADING | 8 +++----- lang/bg.yml | 1 + lang/cs.yml | 1 + lang/da.yml | 1 + lang/de.yml | 1 + lang/en.yml | 1 + lang/es.yml | 1 + lang/fi.yml | 1 + lang/fr.yml | 1 + lang/he.yml | 1 + lang/hu.yml | 1 + lang/it.yml | 1 + lang/ja.yml | 1 + lang/ko.yml | 1 + lang/lt.yml | 1 + lang/nl.yml | 1 + lang/no.yml | 1 + lang/pl.yml | 1 + lang/pt-br.yml | 1 + lang/pt.yml | 1 + lang/ro.yml | 1 + lang/ru.yml | 1 + lang/sr.yml | 1 + lang/sv.yml | 1 + lang/th.yml | 1 + lang/uk.yml | 1 + lang/zh-tw.yml | 1 + lang/zh.yml | 1 + 37 files changed, 89 insertions(+), 32 deletions(-) create mode 100644 config/email.yml.example create mode 100644 config/initializers/40-email.rb diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb index c7c8751d..59b9c67e 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -39,6 +39,7 @@ class SettingsController < ApplicationController end @options = {} @options[:user_format] = User::USER_FORMATS.keys.collect {|f| [User.current.name(f), f.to_s] } + @deliveries = ActionMailer::Base.perform_deliveries end def plugin diff --git a/app/views/settings/_notifications.rhtml b/app/views/settings/_notifications.rhtml index 1a472d60..36701463 100644 --- a/app/views/settings/_notifications.rhtml +++ b/app/views/settings/_notifications.rhtml @@ -1,3 +1,4 @@ +<% if @deliveries %> <% form_tag({:action => 'edit', :tab => 'notifications'}) do %>
@@ -28,3 +29,8 @@ <%= submit_tag l(:button_save) %> <% end %> +<% else %> +
+<%= simple_format(l(:text_email_delivery_not_configured)) %> +
+<% end %> diff --git a/config/email.yml.example b/config/email.yml.example new file mode 100644 index 00000000..a67c1227 --- /dev/null +++ b/config/email.yml.example @@ -0,0 +1,21 @@ +# Outgoing email settings + +production: + delivery_method: :smtp + smtp_settings: + address: smtp.somenet.foo + port: 25 + domain: somenet.foo + authentication: :login + user_name: redmine@somenet.foo + password: redmine + +development: + delivery_method: :smtp + smtp_settings: + address: 127.0.0.1 + port: 25 + domain: somenet.foo + authentication: :login + user_name: redmine@somenet.foo + password: redmine diff --git a/config/environment.rb b/config/environment.rb index b0f16c3e..9a3bf4b1 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -49,25 +49,9 @@ Rails::Initializer.run do |config| # Use Active Record's schema dumper instead of SQL when creating the test database # (enables use of different database adapters for development and test environments) # config.active_record.schema_format = :ruby - - # See Rails::Configuration for more options - # SMTP server configuration - config.action_mailer.smtp_settings = { - :address => "127.0.0.1", - :port => 25, - :domain => "somenet.foo", - :authentication => :login, - :user_name => "redmine@somenet.foo", - :password => "redmine", - } - - config.action_mailer.perform_deliveries = true - - # Tell ActionMailer not to deliver emails to the real world. - # The :test delivery method accumulates sent emails in the - # ActionMailer::Base.deliveries array. - #config.action_mailer.delivery_method = :test - config.action_mailer.delivery_method = :smtp - + # Deliveries are disabled by default. Do NOT modify this section. + # Define your email configuration in email.yml instead. + # It will automatically turn deliveries on + config.action_mailer.perform_deliveries = false end diff --git a/config/environments/test.rb b/config/environments/test.rb index 9ba9ae0f..7c821da0 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -13,4 +13,5 @@ config.whiny_nils = true config.action_controller.consider_all_requests_local = true config.action_controller.perform_caching = false +config.action_mailer.perform_deliveries = true config.action_mailer.delivery_method = :test diff --git a/config/environments/test_pgsql.rb b/config/environments/test_pgsql.rb index 35bb19be..7c821da0 100644 --- a/config/environments/test_pgsql.rb +++ b/config/environments/test_pgsql.rb @@ -13,4 +13,5 @@ config.whiny_nils = true config.action_controller.consider_all_requests_local = true config.action_controller.perform_caching = false -config.action_mailer.delivery_method = :test \ No newline at end of file +config.action_mailer.perform_deliveries = true +config.action_mailer.delivery_method = :test diff --git a/config/environments/test_sqlite3.rb b/config/environments/test_sqlite3.rb index 35bb19be..7c821da0 100644 --- a/config/environments/test_sqlite3.rb +++ b/config/environments/test_sqlite3.rb @@ -13,4 +13,5 @@ config.whiny_nils = true config.action_controller.consider_all_requests_local = true config.action_controller.perform_caching = false -config.action_mailer.delivery_method = :test \ No newline at end of file +config.action_mailer.perform_deliveries = true +config.action_mailer.delivery_method = :test diff --git a/config/initializers/40-email.rb b/config/initializers/40-email.rb new file mode 100644 index 00000000..5b388ec5 --- /dev/null +++ b/config/initializers/40-email.rb @@ -0,0 +1,17 @@ +# Loads action_mailer settings from email.yml +# and turns deliveries on if configuration file is found + +filename = File.join(File.dirname(__FILE__), '..', 'email.yml') +if File.file?(filename) + mailconfig = YAML::load_file(filename) + + if mailconfig.is_a?(Hash) && mailconfig.has_key?(Rails.env) + # Enable deliveries + ActionMailer::Base.perform_deliveries = true + + mailconfig[Rails.env].each do |k, v| + v.symbolize_keys! if v.respond_to?(:symbolize_keys!) + ActionMailer::Base.send("#{k}=", v) + end + end +end diff --git a/doc/INSTALL b/doc/INSTALL index 87a2b38d..13502f8d 100644 --- a/doc/INSTALL +++ b/doc/INSTALL @@ -53,10 +53,10 @@ Optional: trackers, statuses, workflow) and adjust application settings -== SMTP server Configuration - -In config/environment.rb, you can set parameters for your SMTP server: -config.action_mailer.smtp_settings: SMTP server configuration -config.action_mailer.perform_deliveries: set to false to disable mail delivering +== Email delivery Configuration +Copy config/email.yml.example to config/email.yml and edit this file +to adjust your SMTP settings. Don't forget to restart the application after any change to this file. + +Please do not enter your SMTP settings in environment.rb. diff --git a/doc/UPGRADING b/doc/UPGRADING index 2edb2952..1dd90117 100644 --- a/doc/UPGRADING +++ b/doc/UPGRADING @@ -10,15 +10,13 @@ http://www.redmine.org/ 1. Uncompress the program archive in a new directory 3. Copy your database settings (RAILS_ROOT/config/database.yml) + and SMTP settings (RAILS_ROOT/config/email.yml) into the new config directory -4. Enter your SMTP settings in config/environment.rb - Do not replace this file with the old one - -5. Migrate your database (please make a backup before doing this): +4. Migrate your database (please make a backup before doing this): rake db:migrate RAILS_ENV="production" -6. Copy the RAILS_ROOT/files directory content into your new installation +5. Copy the RAILS_ROOT/files directory content into your new installation This directory contains all the attached files diff --git a/lang/bg.yml b/lang/bg.yml index fd6e7e6c..c87e3beb 100644 --- a/lang/bg.yml +++ b/lang/bg.yml @@ -631,3 +631,4 @@ label_incoming_emails: Incoming emails label_generate_key: Generate a key setting_mail_handler_api_enabled: Enable WS for incoming emails setting_mail_handler_api_key: API key +text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." diff --git a/lang/cs.yml b/lang/cs.yml index 2c760722..6669c6cf 100644 --- a/lang/cs.yml +++ b/lang/cs.yml @@ -636,3 +636,4 @@ label_incoming_emails: Incoming emails label_generate_key: Generate a key setting_mail_handler_api_enabled: Enable WS for incoming emails setting_mail_handler_api_key: API key +text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." diff --git a/lang/da.yml b/lang/da.yml index d51d3081..cf40e176 100644 --- a/lang/da.yml +++ b/lang/da.yml @@ -633,3 +633,4 @@ label_incoming_emails: Incoming emails label_generate_key: Generate a key setting_mail_handler_api_enabled: Enable WS for incoming emails setting_mail_handler_api_key: API key +text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." diff --git a/lang/de.yml b/lang/de.yml index 2bc0a16f..adc3dd4e 100644 --- a/lang/de.yml +++ b/lang/de.yml @@ -632,3 +632,4 @@ label_incoming_emails: Incoming emails label_generate_key: Generate a key setting_mail_handler_api_enabled: Enable WS for incoming emails setting_mail_handler_api_key: API key +text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." diff --git a/lang/en.yml b/lang/en.yml index 180a7056..79109467 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -606,6 +606,7 @@ text_reassign_time_entries: 'Reassign reported hours to this issue:' text_user_wrote: '%s wrote:' text_enumeration_destroy_question: '%d objects are assigned to this value.' text_enumeration_category_reassign_to: 'Reassign them to this value:' +text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." default_role_manager: Manager default_role_developper: Developer diff --git a/lang/es.yml b/lang/es.yml index 44d48190..4205402e 100644 --- a/lang/es.yml +++ b/lang/es.yml @@ -634,3 +634,4 @@ label_incoming_emails: Incoming emails label_generate_key: Generate a key setting_mail_handler_api_enabled: Enable WS for incoming emails setting_mail_handler_api_key: API key +text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." diff --git a/lang/fi.yml b/lang/fi.yml index 27f3415c..b69b0755 100644 --- a/lang/fi.yml +++ b/lang/fi.yml @@ -631,3 +631,4 @@ label_incoming_emails: Incoming emails label_generate_key: Generate a key setting_mail_handler_api_enabled: Enable WS for incoming emails setting_mail_handler_api_key: API key +text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." diff --git a/lang/fr.yml b/lang/fr.yml index 89b0b4c8..5b0f04fb 100644 --- a/lang/fr.yml +++ b/lang/fr.yml @@ -606,6 +606,7 @@ text_reassign_time_entries: 'Reporter les heures sur cette demande:' text_user_wrote: '%s a écrit:' text_enumeration_destroy_question: 'Cette valeur est affectée à %d objets.' text_enumeration_category_reassign_to: 'Réaffecter les objets à cette valeur:' +text_email_delivery_not_configured: "L'envoi de mail n'est pas configuré, les notifications sont désactivées.\nConfigurez votre serveur SMTP dans config/email.yml et redémarrez l'application pour les activer." default_role_manager: Manager default_role_developper: Développeur diff --git a/lang/he.yml b/lang/he.yml index 501cfdc9..030e09dc 100644 --- a/lang/he.yml +++ b/lang/he.yml @@ -631,3 +631,4 @@ label_incoming_emails: Incoming emails label_generate_key: Generate a key setting_mail_handler_api_enabled: Enable WS for incoming emails setting_mail_handler_api_key: API key +text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." diff --git a/lang/hu.yml b/lang/hu.yml index 6f88eb96..046916b7 100644 --- a/lang/hu.yml +++ b/lang/hu.yml @@ -632,3 +632,4 @@ label_incoming_emails: Beérkezett levelek label_generate_key: Kulcs generálása setting_mail_handler_api_enabled: Web Service engedélyezése a beérkezett levelekhez setting_mail_handler_api_key: API kulcs +text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." diff --git a/lang/it.yml b/lang/it.yml index 14dc86ff..eb835400 100644 --- a/lang/it.yml +++ b/lang/it.yml @@ -631,3 +631,4 @@ label_incoming_emails: Incoming emails label_generate_key: Generate a key setting_mail_handler_api_enabled: Enable WS for incoming emails setting_mail_handler_api_key: API key +text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." diff --git a/lang/ja.yml b/lang/ja.yml index 5bdc3b55..cba410f6 100644 --- a/lang/ja.yml +++ b/lang/ja.yml @@ -632,3 +632,4 @@ label_incoming_emails: Incoming emails label_generate_key: Generate a key setting_mail_handler_api_enabled: Enable WS for incoming emails setting_mail_handler_api_key: API key +text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." diff --git a/lang/ko.yml b/lang/ko.yml index 8e0d35ef..2b5b0eb0 100644 --- a/lang/ko.yml +++ b/lang/ko.yml @@ -631,3 +631,4 @@ label_incoming_emails: Incoming emails label_generate_key: Generate a key setting_mail_handler_api_enabled: Enable WS for incoming emails setting_mail_handler_api_key: API key +text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." diff --git a/lang/lt.yml b/lang/lt.yml index 0f80a94d..52b6b6fc 100644 --- a/lang/lt.yml +++ b/lang/lt.yml @@ -634,3 +634,4 @@ label_generate_key: Generuoti raktą setting_mail_handler_api_enabled: Įgalinti WS įeinantiems laiškams setting_mail_handler_api_key: API raktas +text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." diff --git a/lang/nl.yml b/lang/nl.yml index d1facc7a..09cdc3c0 100644 --- a/lang/nl.yml +++ b/lang/nl.yml @@ -632,3 +632,4 @@ label_incoming_emails: Incoming emails label_generate_key: Generate a key setting_mail_handler_api_enabled: Enable WS for incoming emails setting_mail_handler_api_key: API key +text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." diff --git a/lang/no.yml b/lang/no.yml index bf25a15a..eb1ff59c 100644 --- a/lang/no.yml +++ b/lang/no.yml @@ -632,3 +632,4 @@ label_incoming_emails: Incoming emails label_generate_key: Generate a key setting_mail_handler_api_enabled: Enable WS for incoming emails setting_mail_handler_api_key: API key +text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." diff --git a/lang/pl.yml b/lang/pl.yml index 28c5f19d..9c5a382b 100644 --- a/lang/pl.yml +++ b/lang/pl.yml @@ -631,3 +631,4 @@ label_incoming_emails: Incoming emails label_generate_key: Generate a key setting_mail_handler_api_enabled: Enable WS for incoming emails setting_mail_handler_api_key: API key +text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." diff --git a/lang/pt-br.yml b/lang/pt-br.yml index 04c3b347..1582e568 100644 --- a/lang/pt-br.yml +++ b/lang/pt-br.yml @@ -631,3 +631,4 @@ label_incoming_emails: Incoming emails label_generate_key: Generate a key setting_mail_handler_api_enabled: Enable WS for incoming emails setting_mail_handler_api_key: API key +text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." diff --git a/lang/pt.yml b/lang/pt.yml index 5a1ffc2e..a5b703fc 100644 --- a/lang/pt.yml +++ b/lang/pt.yml @@ -631,3 +631,4 @@ label_incoming_emails: Incoming emails label_generate_key: Generate a key setting_mail_handler_api_enabled: Enable WS for incoming emails setting_mail_handler_api_key: API key +text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." diff --git a/lang/ro.yml b/lang/ro.yml index 3a1696c7..3fa154d4 100644 --- a/lang/ro.yml +++ b/lang/ro.yml @@ -631,3 +631,4 @@ label_incoming_emails: Incoming emails label_generate_key: Generate a key setting_mail_handler_api_enabled: Enable WS for incoming emails setting_mail_handler_api_key: API key +text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." diff --git a/lang/ru.yml b/lang/ru.yml index 7d0707f7..5d59ec1f 100644 --- a/lang/ru.yml +++ b/lang/ru.yml @@ -635,3 +635,4 @@ label_incoming_emails: Incoming emails label_generate_key: Generate a key setting_mail_handler_api_enabled: Enable WS for incoming emails setting_mail_handler_api_key: API key +text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." diff --git a/lang/sr.yml b/lang/sr.yml index 5b8e5d93..fa1b4d84 100644 --- a/lang/sr.yml +++ b/lang/sr.yml @@ -632,3 +632,4 @@ label_incoming_emails: Incoming emails label_generate_key: Generate a key setting_mail_handler_api_enabled: Enable WS for incoming emails setting_mail_handler_api_key: API key +text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." diff --git a/lang/sv.yml b/lang/sv.yml index 4c6170f4..9015099e 100644 --- a/lang/sv.yml +++ b/lang/sv.yml @@ -632,3 +632,4 @@ label_incoming_emails: Incoming emails label_generate_key: Generate a key setting_mail_handler_api_enabled: Enable WS for incoming emails setting_mail_handler_api_key: API key +text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." diff --git a/lang/th.yml b/lang/th.yml index e7f276a3..27f7b14c 100644 --- a/lang/th.yml +++ b/lang/th.yml @@ -634,3 +634,4 @@ label_incoming_emails: Incoming emails label_generate_key: Generate a key setting_mail_handler_api_enabled: Enable WS for incoming emails setting_mail_handler_api_key: API key +text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." diff --git a/lang/uk.yml b/lang/uk.yml index 275de0e4..0286779b 100644 --- a/lang/uk.yml +++ b/lang/uk.yml @@ -633,3 +633,4 @@ label_incoming_emails: Incoming emails label_generate_key: Generate a key setting_mail_handler_api_enabled: Enable WS for incoming emails setting_mail_handler_api_key: API key +text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." diff --git a/lang/zh-tw.yml b/lang/zh-tw.yml index 9b43ed45..0e8fabef 100644 --- a/lang/zh-tw.yml +++ b/lang/zh-tw.yml @@ -632,3 +632,4 @@ default_activity_development: 開發 enumeration_issue_priorities: 項目優先權 enumeration_doc_categories: 文件分類 enumeration_activities: 活動 (時間追蹤) +text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." diff --git a/lang/zh.yml b/lang/zh.yml index 2bd0880a..1cde9f50 100644 --- a/lang/zh.yml +++ b/lang/zh.yml @@ -632,3 +632,4 @@ default_activity_development: 开发 enumeration_issue_priorities: 问题优先级 enumeration_doc_categories: 文档类别 enumeration_activities: 活动(时间跟踪) +text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."