Skip to content

Commit

Permalink
Mua: support 465 port connections (#4606)
Browse files Browse the repository at this point in the history
* mua: support 465 port connections

* allow port=465 but SMTP_HOST_SSL_ENABLED=false
  • Loading branch information
ruslandoga authored Sep 24, 2024
1 parent dca2eb5 commit 09c74ee
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
17 changes: 15 additions & 2 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -641,8 +641,21 @@ case mailer_adapter do
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
port = get_int_from_path_or_env(config_dir, "SMTP_HOST_PORT", 587)

ssl_enabled =
if ssl_enabled = get_var_from_path_or_env(config_dir, "SMTP_HOST_SSL_ENABLED") do
String.to_existing_atom(ssl_enabled)
end

protocol =
cond do
ssl_enabled -> :ssl
is_nil(ssl_enabled) and port == 465 -> :ssl
true -> :tcp
end

config :plausible, Plausible.Mailer, protocol: protocol, relay: relay, port: port
end

username = get_var_from_path_or_env(config_dir, "SMTP_USER_NAME")
Expand Down
41 changes: 41 additions & 0 deletions test/plausible/config_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,52 @@ defmodule Plausible.ConfigTest do
assert get_in(runtime_config(env), [:plausible, Plausible.Mailer]) == [
{:adapter, Bamboo.Mua},
{:ssl, [middlebox_comp_mode: false]},
{:protocol, :tcp},
{:relay, "localhost"},
{:port, 2525},
{:auth, [username: "neo", password: "one"]}
]
end

test "Bamboo.Mua (ssl relay config)" do
env = [
{"MAILER_ADAPTER", "Bamboo.Mua"},
{"SMTP_HOST_ADDR", "localhost"},
{"SMTP_HOST_PORT", "2525"},
{"SMTP_HOST_SSL_ENABLED", "true"},
{"SMTP_USER_NAME", "neo"},
{"SMTP_USER_PWD", "one"}
]

assert get_in(runtime_config(env), [:plausible, Plausible.Mailer]) == [
{:adapter, Bamboo.Mua},
{:ssl, [middlebox_comp_mode: false]},
{:protocol, :ssl},
{:relay, "localhost"},
{:port, 2525},
{:auth, [username: "neo", password: "one"]}
]
end

test "Bamboo.Mua (port=465 relay config)" do
env = [
{"MAILER_ADAPTER", "Bamboo.Mua"},
{"SMTP_HOST_ADDR", "localhost"},
{"SMTP_HOST_PORT", "465"},
{"SMTP_USER_NAME", "neo"},
{"SMTP_USER_PWD", "one"}
]

assert get_in(runtime_config(env), [:plausible, Plausible.Mailer]) == [
{:adapter, Bamboo.Mua},
{:ssl, [middlebox_comp_mode: false]},
{:protocol, :ssl},
{:relay, "localhost"},
{:port, 465},
{:auth, [username: "neo", password: "one"]}
]
end

test "Bamboo.Mua (no auth relay config)" do
env = [
{"MAILER_ADAPTER", "Bamboo.Mua"},
Expand All @@ -186,6 +226,7 @@ defmodule Plausible.ConfigTest do
assert get_in(runtime_config(env), [:plausible, Plausible.Mailer]) == [
adapter: Bamboo.Mua,
ssl: [middlebox_comp_mode: false],
protocol: :tcp,
relay: "localhost",
port: 2525
]
Expand Down

0 comments on commit 09c74ee

Please sign in to comment.