From 4ed0d529b3103748115aaa8d77e208d2bf852f46 Mon Sep 17 00:00:00 2001 From: Scott Martineau Date: Mon, 27 Apr 2026 20:51:42 -0600 Subject: [PATCH] fix: use account-level "Send from Email" setting over SMTP_FROM env var MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The account-level SMTP config (configured via Settings > Email) was ignored when Rails-level SMTP delivery was also configured. The env var early-return path ran before the DB config lookup, so the "Send from Email" field had no effect — emails were sent from the SMTP username instead. Move the account-level DB config check before the env var fallback so the UI setting takes precedence. SMTP_FROM env var still works as a fallback when no account-level config exists. Also guard against missing SMTP_FROM with a default empty string to avoid KeyError when the env var is unset and no DB config is present. Fixes #598 --- lib/action_mailer_configs_interceptor.rb | 34 ++++++++++++++---------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/lib/action_mailer_configs_interceptor.rb b/lib/action_mailer_configs_interceptor.rb index 5b2ad19b..23550922 100644 --- a/lib/action_mailer_configs_interceptor.rb +++ b/lib/action_mailer_configs_interceptor.rb @@ -15,18 +15,6 @@ module ActionMailerConfigsInterceptor return message end - if Rails.env.production? && Rails.application.config.action_mailer.delivery_method - from = ENV.fetch('SMTP_FROM').to_s.split(',').sample - - if from.match?(User::FULL_EMAIL_REGEXP) - message[:from] = message[:from].to_s.sub(User::EMAIL_REGEXP, from) - else - message.from = from - end - - return message - end - unless Docuseal.multitenant? email_configs = EncryptedConfig.order(:account_id).find_by(key: EncryptedConfig::EMAIL_SMTP_KEY) @@ -34,11 +22,29 @@ module ActionMailerConfigsInterceptor message.delivery_method(:smtp, build_smtp_configs_hash(email_configs)) message.from = %("#{email_configs.account.name.to_s.delete('"')}" <#{email_configs.value['from_email']}>) - else - message.delivery_method(:test) + + return message end end + if Rails.application.config.action_mailer.delivery_method + from = ENV.fetch('SMTP_FROM', '').to_s.split(',').sample + + if from.present? + if from.match?(User::FULL_EMAIL_REGEXP) + message[:from] = message[:from].to_s.sub(User::EMAIL_REGEXP, from) + else + message.from = from + end + end + + return message + end + + unless Docuseal.multitenant? + message.delivery_method(:test) + end + message end