Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change SMTP defaults #4538

Merged
merged 7 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
40 changes: 25 additions & 15 deletions test/plausible/config_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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]) == "[email protected]"
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]) ==
"[email protected]"
end

test "mailer email custom" do
Expand All @@ -16,29 +23,20 @@ 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", "[email protected]"}, {"MAILER_NAME", "John"}]

assert get_in(runtime_config(env), [:plausible, :mailer_email]) ==
{"John", "[email protected]"}
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

Expand Down Expand Up @@ -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

Expand All @@ -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"]}
Expand All @@ -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
]
Expand Down
Loading