Fix relay-without-auth MUA config (#4298)

This commit is contained in:
ruslandoga 2024-07-15 17:01:57 +07:00 committed by GitHub
parent 922b9ab4d6
commit 530951780c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 35 additions and 8 deletions

View File

@ -504,13 +504,24 @@ case mailer_adapter do
if relay = get_var_from_path_or_env(config_dir, "SMTP_HOST_ADDR") do
port = get_int_from_path_or_env(config_dir, "SMTP_HOST_PORT", 25)
config :plausible, Plausible.Mailer, relay: relay, port: port
end
username = get_var_from_path_or_env(config_dir, "SMTP_USER_NAME")
password = get_var_from_path_or_env(config_dir, "SMTP_USER_PWD")
config :plausible, Plausible.Mailer,
auth: [username: username, password: password],
relay: relay,
port: port
cond do
username && password ->
config :plausible, Plausible.Mailer, auth: [username: username, password: password]
username || password ->
raise ArgumentError, """
Both SMTP_USER_NAME and SMTP_USER_PWD must be set for SMTP authentication.
Please provide values for both environment variables.
"""
_both_nil = true ->
nil
end
"Bamboo.LocalAdapter" ->

View File

@ -159,9 +159,25 @@ defmodule Plausible.ConfigTest do
assert get_in(runtime_config(env), [:plausible, Plausible.Mailer]) == [
{:adapter, Bamboo.Mua},
{:auth, [username: "neo", password: "one"]},
{:relay, "localhost"},
{:port, 2525}
{:port, 2525},
{:auth, [username: "neo", password: "one"]}
]
end
test "Bamboo.Mua (no auth relay config)" do
env = [
{"MAILER_ADAPTER", "Bamboo.Mua"},
{"SMTP_HOST_ADDR", "localhost"},
{"SMTP_HOST_PORT", "2525"},
{"SMTP_USER_NAME", nil},
{"SMTP_USER_PWD", nil}
]
assert get_in(runtime_config(env), [:plausible, Plausible.Mailer]) == [
adapter: Bamboo.Mua,
relay: "localhost",
port: 2525
]
end