Skip to content

Commit 09c74ee

Browse files
authored
Mua: support 465 port connections (#4606)
* mua: support 465 port connections * allow port=465 but SMTP_HOST_SSL_ENABLED=false
1 parent dca2eb5 commit 09c74ee

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

config/runtime.exs

+15-2
Original file line numberDiff line numberDiff line change
@@ -641,8 +641,21 @@ case mailer_adapter do
641641
config :plausible, Plausible.Mailer, ssl: [middlebox_comp_mode: middlebox_comp_mode]
642642

643643
if relay = get_var_from_path_or_env(config_dir, "SMTP_HOST_ADDR") do
644-
port = get_int_from_path_or_env(config_dir, "SMTP_HOST_PORT", 25)
645-
config :plausible, Plausible.Mailer, relay: relay, port: port
644+
port = get_int_from_path_or_env(config_dir, "SMTP_HOST_PORT", 587)
645+
646+
ssl_enabled =
647+
if ssl_enabled = get_var_from_path_or_env(config_dir, "SMTP_HOST_SSL_ENABLED") do
648+
String.to_existing_atom(ssl_enabled)
649+
end
650+
651+
protocol =
652+
cond do
653+
ssl_enabled -> :ssl
654+
is_nil(ssl_enabled) and port == 465 -> :ssl
655+
true -> :tcp
656+
end
657+
658+
config :plausible, Plausible.Mailer, protocol: protocol, relay: relay, port: port
646659
end
647660

648661
username = get_var_from_path_or_env(config_dir, "SMTP_USER_NAME")

test/plausible/config_test.exs

+41
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,52 @@ defmodule Plausible.ConfigTest do
168168
assert get_in(runtime_config(env), [:plausible, Plausible.Mailer]) == [
169169
{:adapter, Bamboo.Mua},
170170
{:ssl, [middlebox_comp_mode: false]},
171+
{:protocol, :tcp},
171172
{:relay, "localhost"},
172173
{:port, 2525},
173174
{:auth, [username: "neo", password: "one"]}
174175
]
175176
end
176177

178+
test "Bamboo.Mua (ssl relay config)" do
179+
env = [
180+
{"MAILER_ADAPTER", "Bamboo.Mua"},
181+
{"SMTP_HOST_ADDR", "localhost"},
182+
{"SMTP_HOST_PORT", "2525"},
183+
{"SMTP_HOST_SSL_ENABLED", "true"},
184+
{"SMTP_USER_NAME", "neo"},
185+
{"SMTP_USER_PWD", "one"}
186+
]
187+
188+
assert get_in(runtime_config(env), [:plausible, Plausible.Mailer]) == [
189+
{:adapter, Bamboo.Mua},
190+
{:ssl, [middlebox_comp_mode: false]},
191+
{:protocol, :ssl},
192+
{:relay, "localhost"},
193+
{:port, 2525},
194+
{:auth, [username: "neo", password: "one"]}
195+
]
196+
end
197+
198+
test "Bamboo.Mua (port=465 relay config)" do
199+
env = [
200+
{"MAILER_ADAPTER", "Bamboo.Mua"},
201+
{"SMTP_HOST_ADDR", "localhost"},
202+
{"SMTP_HOST_PORT", "465"},
203+
{"SMTP_USER_NAME", "neo"},
204+
{"SMTP_USER_PWD", "one"}
205+
]
206+
207+
assert get_in(runtime_config(env), [:plausible, Plausible.Mailer]) == [
208+
{:adapter, Bamboo.Mua},
209+
{:ssl, [middlebox_comp_mode: false]},
210+
{:protocol, :ssl},
211+
{:relay, "localhost"},
212+
{:port, 465},
213+
{:auth, [username: "neo", password: "one"]}
214+
]
215+
end
216+
177217
test "Bamboo.Mua (no auth relay config)" do
178218
env = [
179219
{"MAILER_ADAPTER", "Bamboo.Mua"},
@@ -186,6 +226,7 @@ defmodule Plausible.ConfigTest do
186226
assert get_in(runtime_config(env), [:plausible, Plausible.Mailer]) == [
187227
adapter: Bamboo.Mua,
188228
ssl: [middlebox_comp_mode: false],
229+
protocol: :tcp,
189230
relay: "localhost",
190231
port: 2525
191232
]

0 commit comments

Comments
 (0)