diff --git a/app/mailers/group_smtp_mailer.rb b/app/mailers/group_smtp_mailer.rb index 5cd5836752a..708e46043f5 100644 --- a/app/mailers/group_smtp_mailer.rb +++ b/app/mailers/group_smtp_mailer.rb @@ -18,6 +18,8 @@ class GroupSmtpMailer < ActionMailer::Base authentication: GlobalSetting.smtp_authentication, enable_starttls_auto: from_group.smtp_ssl, return_response: true, + open_timeout: GlobalSetting.group_smtp_open_timeout, + read_timeout: GlobalSetting.group_smtp_read_timeout, } group_name = from_group.name_full_preferred diff --git a/config/discourse_defaults.conf b/config/discourse_defaults.conf index b0f9a466f1c..9fd3f0208a4 100644 --- a/config/discourse_defaults.conf +++ b/config/discourse_defaults.conf @@ -98,6 +98,14 @@ smtp_open_timeout = 5 # Number of seconds to wait until timing-out a SMTP read(2) call smtp_read_timeout = 5 +# number of seconds to wait while attempting to open a SMTP connection only when +# sending emails via group SMTP +group_smtp_open_timeout = 30 + +# Number of seconds to wait until timing-out a SMTP read(2) call only when sending +# emails via group SMTP +group_smtp_read_timeout = 60 + # load MiniProfiler in production, to be used by developers load_mini_profiler = true diff --git a/spec/mailers/group_smtp_mailer_spec.rb b/spec/mailers/group_smtp_mailer_spec.rb index ecd6d945099..09bbf72489c 100644 --- a/spec/mailers/group_smtp_mailer_spec.rb +++ b/spec/mailers/group_smtp_mailer_spec.rb @@ -117,6 +117,24 @@ RSpec.describe GroupSmtpMailer do expect(sent_mail.subject).to eq("Re: Hello from John") end + it "configures delivery options for SMTP correctly" do + mail = GroupSmtpMailer.send_mail(group, user.email, Fabricate(:post)) + expect(mail.delivery_method.settings).to eq( + { + address: "smtp.gmail.com", + port: 587, + domain: "gmail.com", + user_name: "bugs@gmail.com", + password: "super$secret$password", + authentication: GlobalSetting.smtp_authentication, + enable_starttls_auto: true, + return_response: true, + open_timeout: GlobalSetting.group_smtp_open_timeout, + read_timeout: GlobalSetting.group_smtp_read_timeout, + }, + ) + end + context "when the site has a reply by email address configured" do before do SiteSetting.manual_polling_enabled = true