mirror of
https://github.com/plausible/analytics.git
synced 2024-12-24 01:54:34 +03:00
Fix relay-without-auth MUA config (#4298)
This commit is contained in:
parent
922b9ab4d6
commit
530951780c
@ -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" ->
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user