DEV: Add env var for local email port (#36900)

This commit adds DISCOURSE_LOCAL_EMAIL_PORT
environment variable to allow setting a port other than 1025 for local
mail.
This is added because now macOS has a system service using port 1025,
causing conflicts when running a local mail server for Discourse
development.
This commit is contained in:
Martin Brennan
2025-12-31 14:25:02 +10:00
committed by GitHub
parent e2dd3870b4
commit 867c2f0096
3 changed files with 9 additions and 4 deletions
+2 -1
View File
@@ -8,6 +8,7 @@ Rails.application.initialize!
# When in "dev" mode, ensure we won't be sending any emails
if Rails.env.development? && !GlobalSetting.try(:use_smtp_environment_in_development) &&
ActionMailer::Base.smtp_settings.slice(:address, :port) != { address: "localhost", port: 1025 }
ActionMailer::Base.smtp_settings.slice(:address, :port) !=
{ address: "localhost", port: ENV["DISCOURSE_LOCAL_EMAIL_PORT"] || 1025 }
fail "In development mode, you should be using a local development mail server to avoid unintentionally sending real mail"
end
+3 -2
View File
@@ -39,10 +39,11 @@ Discourse::Application.configure do
config.action_mailer.smtp_settings =
if GlobalSetting.try(:use_smtp_environment_in_development)
GlobalSetting.smtp_settings || { address: "localhost", port: 1025 }
GlobalSetting.smtp_settings ||
{ address: "localhost", port: ENV["DISCOURSE_LOCAL_EMAIL_PORT"] || 1025 }
else
# we recommend you use mailpit: https://github.com/axllent/mailpit/
{ address: "localhost", port: 1025 }
{ address: "localhost", port: ENV["DISCOURSE_LOCAL_EMAIL_PORT"] || 1025 }
end
config.action_mailer.raise_delivery_errors = true
+4 -1
View File
@@ -30,7 +30,10 @@ Discourse::Application.configure do
config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for nginx
# we recommend you use mailhog https://github.com/mailhog/MailHog
config.action_mailer.smtp_settings = { address: "localhost", port: 1025 }
config.action_mailer.smtp_settings = {
address: "localhost",
port: ENV["DISCOURSE_LOCAL_EMAIL_PORT"] || 1025,
}
# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify