Change SMTP defaults (#4538)

* default smtp config updates

* tests

* improve SMTP_MIDDLEBOX_COMP_MODE decoding

* changelog

* format

---------

Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com>
This commit is contained in:
ruslandoga 2024-09-06 15:31:23 +07:00 committed by GitHub
parent 4864a2c30e
commit 67d7c6522c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 36 additions and 17 deletions

View File

@ -128,6 +128,8 @@ All notable changes to this project will be documented in this file.
- Replace `CLICKHOUSE_MAX_BUFFER_SIZE` with `CLICKHOUSE_MAX_BUFFER_SIZE_BYTES`
- Validate metric isn't queried multiple times
- Filters in dashboard are represented by jsonurl
- `MAILER_EMAIL` now defaults to an address built off of `BASE_URL` plausible/analytics#4538
- default `MAILER_ADAPTER` has been changed to `Bamboo.Mua` plausible/analytics#4538
### Fixed
- Creating many sites no longer leads to cookie overflow

View File

@ -99,8 +99,8 @@ super_admin_user_ids =
|> Enum.filter(& &1)
env = get_var_from_path_or_env(config_dir, "ENVIRONMENT", "prod")
mailer_adapter = get_var_from_path_or_env(config_dir, "MAILER_ADAPTER", "Bamboo.SMTPAdapter")
mailer_email = get_var_from_path_or_env(config_dir, "MAILER_EMAIL", "hello@plausible.local")
mailer_adapter = get_var_from_path_or_env(config_dir, "MAILER_ADAPTER", "Bamboo.Mua")
mailer_email = get_var_from_path_or_env(config_dir, "MAILER_EMAIL", "plausible@#{base_url.host}")
mailer_email =
if mailer_name = get_var_from_path_or_env(config_dir, "MAILER_NAME") do
@ -536,6 +536,13 @@ case mailer_adapter do
"Bamboo.Mua" ->
config :plausible, Plausible.Mailer, adapter: Bamboo.Mua
# prevents common problems with Erlang's TLS v1.3
middlebox_comp_mode =
get_var_from_path_or_env(config_dir, "SMTP_MIDDLEBOX_COMP_MODE", "false")
middlebox_comp_mode = String.to_existing_atom(middlebox_comp_mode)
config :plausible, Plausible.Mailer, ssl: [middlebox_comp_mode: middlebox_comp_mode]
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

View File

@ -4,7 +4,14 @@ defmodule Plausible.ConfigTest do
describe "mailer" do
test "mailer email default" do
env = [{"MAILER_EMAIL", nil}]
assert get_in(runtime_config(env), [:plausible, :mailer_email]) == "hello@plausible.local"
assert get_in(runtime_config(env), [:plausible, :mailer_email]) == "plausible@localhost"
end
test "mailer email from base url" do
env = [{"MAILER_EMAIL", nil}, {"BASE_URL", "https://plausible.example.com:8443"}]
assert get_in(runtime_config(env), [:plausible, :mailer_email]) ==
"plausible@plausible.example.com"
end
test "mailer email custom" do
@ -16,7 +23,7 @@ defmodule Plausible.ConfigTest do
env = [{"MAILER_EMAIL", nil}, {"MAILER_NAME", "John"}]
assert get_in(runtime_config(env), [:plausible, :mailer_email]) ==
{"John", "hello@plausible.local"}
{"John", "plausible@localhost"}
env = [{"MAILER_EMAIL", "custom@mailer.email"}, {"MAILER_NAME", "John"}]
@ -24,21 +31,12 @@ defmodule Plausible.ConfigTest do
{"John", "custom@mailer.email"}
end
test "defaults to Bamboo.SMTPAdapter" do
test "defaults to Bamboo.Mua" do
env = {"MAILER_ADAPTER", nil}
assert get_in(runtime_config(env), [:plausible, Plausible.Mailer]) == [
adapter: Bamboo.SMTPAdapter,
server: "mail",
hostname: "localhost",
port: "25",
username: nil,
password: nil,
tls: :if_available,
allowed_tls_versions: [:tlsv1, :"tlsv1.1", :"tlsv1.2"],
ssl: false,
retries: 2,
no_mx_lookups: true
adapter: Bamboo.Mua,
ssl: [middlebox_comp_mode: false]
]
end
@ -144,7 +142,17 @@ defmodule Plausible.ConfigTest do
env = [{"MAILER_ADAPTER", "Bamboo.Mua"}]
assert get_in(runtime_config(env), [:plausible, Plausible.Mailer]) == [
{:adapter, Bamboo.Mua}
{:adapter, Bamboo.Mua},
{:ssl, [middlebox_comp_mode: false]}
]
end
test "Bamboo.Mua (middlebox_comp_mode enabled)" do
env = [{"MAILER_ADAPTER", "Bamboo.Mua"}, {"SMTP_MIDDLEBOX_COMP_MODE", "true"}]
assert get_in(runtime_config(env), [:plausible, Plausible.Mailer]) == [
{:adapter, Bamboo.Mua},
{:ssl, [middlebox_comp_mode: true]}
]
end
@ -159,6 +167,7 @@ defmodule Plausible.ConfigTest do
assert get_in(runtime_config(env), [:plausible, Plausible.Mailer]) == [
{:adapter, Bamboo.Mua},
{:ssl, [middlebox_comp_mode: false]},
{:relay, "localhost"},
{:port, 2525},
{:auth, [username: "neo", password: "one"]}
@ -176,6 +185,7 @@ defmodule Plausible.ConfigTest do
assert get_in(runtime_config(env), [:plausible, Plausible.Mailer]) == [
adapter: Bamboo.Mua,
ssl: [middlebox_comp_mode: false],
relay: "localhost",
port: 2525
]