fix: use account-level "Send from Email" setting over SMTP_FROM env var

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
pull/641/head
Scott Martineau 1 week ago
parent daaa289a5c
commit 4ed0d529b3

@ -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

Loading…
Cancel
Save