1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Configure a default timeout for the smtp delivery method

The default is set to 5 and only applied for new applications or
applications that opt-in for this new default.

Closes #42089.

[André Luis Leal Cardoso Junior + Rafael Mendonça França]
This commit is contained in:
Rafael Mendonça França 2021-04-28 03:59:19 +00:00
parent cbcface6c0
commit 52db7f2ef3
No known key found for this signature in database
GPG key ID: FC23B6D0F1EEE948
6 changed files with 42 additions and 0 deletions

View file

@ -1,4 +1,6 @@
* Configures a default of 5 for both `open_timeout` and `read_timeout` for SMTP Settings.
*André Luis Leal Cardoso Junior*
Please check [6-1-stable](https://github.com/rails/rails/blob/6-1-stable/actionmailer/CHANGELOG.md) for previous changes.

View file

@ -45,6 +45,15 @@ module ActionMailer
self.delivery_job = delivery_job.constantize
end
if smtp_settings = options.delete(:smtp_settings)
self.smtp_settings = smtp_settings
end
if smtp_timeout = options.delete(:smtp_timeout)
self.smtp_settings[:open_timeout] ||= smtp_timeout
self.smtp_settings[:read_timeout] ||= smtp_timeout
end
options.each { |k, v| send("#{k}=", v) }
end

View file

@ -784,6 +784,9 @@ There are a number of settings available on `config.action_mailer`:
* `:open_timeout` - Number of seconds to wait while attempting to open a connection.
* `:read_timeout` - Number of seconds to wait until timing-out a read(2) call.
* `config.action_mailer.smtp_timeout` allows to configure both the `:open_timeout` and `:read_timeout`
values for `:smtp` delivery method.
* `config.action_mailer.sendmail_settings` allows detailed configuration for the `sendmail` delivery method. It accepts a hash of options, which can include any of these options:
* `:location` - The location of the sendmail executable. Defaults to `/usr/sbin/sendmail`.
* `:arguments` - The command line arguments. Defaults to `-i`.
@ -1063,6 +1066,7 @@ text/javascript image/svg+xml application/postscript application/x-shockwave-fla
- `config.active_support.hash_digest_class`: `OpenSSL::Digest::SHA256`
- `config.active_support.cache_format_version`: `7.0`
- `config.action_dispatch.return_only_request_media_type_on_content_type`: `false`
- `config.action_mailer.smtp_timeout`: `5`
#### For '6.1', defaults from previous versions below and:
@ -1141,6 +1145,7 @@ text/javascript image/svg+xml application/postscript application/x-shockwave-fla
- `config.active_support.cache_format_version`: `6.1`
- `config.action_dispatch.return_only_request_media_type_on_content_type`: `true`
- `ActiveSupport.utc_to_local_returns_utc_offset_times`: `false`
- `config.action_mailer.smtp_timeout`: `nil`
### Configuring a Database

View file

@ -212,6 +212,10 @@ module Rails
active_support.remove_deprecated_time_with_zone_name = true
active_support.cache_format_version = 7.0
end
if respond_to?(:action_mailer)
action_mailer.smtp_timeout = 5
end
else
raise "Unknown version #{target_version.to_s.inspect}"
end

View file

@ -34,3 +34,6 @@
# Only change this value after your application is fully deployed to Rails 7.0
# and you have no plans to rollback.
# config.active_support.cache_format_version = 7.0
# Set both the `:open_timeout` and `:read_timeout` values for `:smtp` delivery method.
# Rails.application.config.action_mailer.smtp_timeout = 5

View file

@ -2666,6 +2666,25 @@ module ApplicationTests
assert_equal 308, Rails.application.config.action_dispatch.ssl_default_redirect_status
end
test "Rails.application.config.action_mailer.smtp_settings have open_timeout and read_timeout defined as 5 in 7.0 defaults" do
remove_from_config '.*config\.load_defaults.*\n'
add_to_config 'config.load_defaults "7.0"'
app "development"
assert_equal 5, ActionMailer::Base.smtp_settings[:open_timeout]
assert_equal 5, ActionMailer::Base.smtp_settings[:read_timeout]
end
test "Rails.application.config.action_mailer.smtp_settings does not have open_timeout and read_timeout configured on other versions" do
remove_from_config '.*config\.load_defaults.*\n'
app "development"
assert_nil ActionMailer::Base.smtp_settings[:open_timeout]
assert_nil ActionMailer::Base.smtp_settings[:read_timeout]
end
test "ActiveSupport.utc_to_local_returns_utc_offset_times is true in 6.1 defaults" do
remove_from_config '.*config\.load_defaults.*\n'
add_to_config 'config.load_defaults "6.1"'