diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index ba669a9a7..6a17668a2 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -8,8 +8,10 @@ class ApplicationMailer < ActionMailer::Base helper AuthenticationHelper before_action :use_custom_host - before_action :set_delivery_options - before_action :set_perform_deliveries + + # [@SRE] temporarily disabled + # before_action :set_delivery_options + # before_action :set_perform_deliveries default( from: -> { email_from }, diff --git a/config/environments/production.rb b/config/environments/production.rb index b693317d4..efa428577 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -127,8 +127,27 @@ Rails.application.configure do protocol = ENV["APP_PROTOCOL"] || "http://" config.action_mailer.delivery_method = :smtp - config.action_mailer.perform_deliveries = false + config.action_mailer.perform_deliveries = true config.action_mailer.default_url_options = { host: protocol + ENV["APP_DOMAIN"].to_s } + ActionMailer::Base.smtp_settings = if ENV["SENDGRID_API_KEY"].present? + { + address: "smtp.sendgrid.net", + port: 587, + authentication: :plain, + user_name: "apikey", + password: ENV["SENDGRID_API_KEY"], + domain: ENV["APP_DOMAIN"] + } + else + { + address: ENV["SMTP_ADDRESS"], + port: ENV["SMTP_PORT"], + authentication: ENV["SMTP_AUTHENTICATION"], + user_name: ENV["SMTP_USER_NAME"], + password: ENV["SMTP_PASSWORD"], + domain: ENV["SMTP_DOMAIN"] + } + end if ENV["HEROKU_APP_URL"].present? && ENV["HEROKU_APP_URL"] != ENV["APP_DOMAIN"] config.middleware.use Rack::HostRedirect, diff --git a/spec/mailers/application_mailer_spec.rb b/spec/mailers/application_mailer_spec.rb index 58c262432..7f8e9970e 100644 --- a/spec/mailers/application_mailer_spec.rb +++ b/spec/mailers/application_mailer_spec.rb @@ -4,7 +4,7 @@ RSpec.describe ApplicationMailer, type: :mailer do let(:user) { create(:user) } let(:email) { VerificationMailer.with(user_id: user.id).account_ownership_verification_email } - describe "#set_perform_deliveries" do + xdescribe "#set_perform_deliveries" do it "changes perform_deliveries from true to false if smtp is not enabled" do expect { email.deliver_now }.to change(described_class, :perform_deliveries).from(true).to(false) end @@ -17,7 +17,7 @@ RSpec.describe ApplicationMailer, type: :mailer do end end - describe "#set_delivery_options" do + xdescribe "#set_delivery_options" do it "evoked Settings::SMTP.settings during callback" do allow(Settings::SMTP).to receive(:settings) email.deliver_now diff --git a/spec/models/settings/smtp_spec.rb b/spec/models/settings/smtp_spec.rb index 2829c0b0b..b0057e4a5 100644 --- a/spec/models/settings/smtp_spec.rb +++ b/spec/models/settings/smtp_spec.rb @@ -1,6 +1,10 @@ require "rails_helper" RSpec.describe Settings::SMTP do + after do + described_class.clear_cache + end + describe "::settings" do it "use default sendgrid config if SENDGRID_API_KEY is available" do key = "something" diff --git a/spec/system/user_logs_in_with_password_spec.rb b/spec/system/user_logs_in_with_password_spec.rb index b6fab144d..7a594f152 100644 --- a/spec/system/user_logs_in_with_password_spec.rb +++ b/spec/system/user_logs_in_with_password_spec.rb @@ -2,6 +2,7 @@ require "rails_helper" RSpec.describe "Authenticating with a password" do def submit_login_form(email, password) + allow(ForemInstance).to receive(:smtp_enabled?).and_return(true) fill_in "Email", with: email fill_in "Password", with: password click_button "Continue"