pentacent / keila

Open Source Newsletter Tool.
https://keila.io
GNU Affero General Public License v3.0
1.25k stars 61 forks source link

no_mx_lookups should be a proper option #303

Open verymilan opened 3 weeks ago

verymilan commented 3 weeks ago

Hi there, for a deployment of ours, it is required to modify the code in order to set no_mx_lookups to true. Otherwise Keila tries to send with mailin instead of mailout. Just now we even realize that the issue reoccured again and i wonder if something changed with a recent release... having this as a proper option to configure would be quite helpful. :)

It looks like it is set tho, but maybe it does not apply to the configured sender anymore?:

$ grep -r no_mx_lookups *
grep: _build/prod/lib/gen_smtp/ebin/gen_smtp_client.beam: binary file matches
grep: _build/prod/lib/swoosh/ebin/Elixir.Swoosh.Adapters.SMTP.beam: binary file matches
_build/prod/rel/keila/releases/0.14.0/runtime.exs:            no_mx_lookups: true
_build/prod/rel/keila/releases/0.14.4/runtime.exs:            no_mx_lookups: true
_build/prod/rel/keila/releases/0.14.5/runtime.exs:            no_mx_lookups: true
_build/prod/rel/keila/releases/0.14.6/runtime.exs:            no_mx_lookups: true
_build/prod/rel/keila/releases/0.14.7/runtime.exs:            no_mx_lookups: true
grep: _build/prod/rel/keila/lib/swoosh-1.11.6/ebin/Elixir.Swoosh.Adapters.SMTP.beam: binary file matches
grep: _build/prod/rel/keila/lib/gen_smtp-1.2.0/ebin/gen_smtp_client.beam: binary file matches
config/runtime.exs:            no_mx_lookups: true
deps/swoosh/lib/swoosh/adapters/smtp.ex:        no_mx_lookups: false
deps/swoosh/lib/swoosh/adapters/smtp.ex:    no_mx_lookups: {&String.to_atom/1, [true, false]}
deps/swoosh/lib/swoosh/adapters/proton_bridge.ex:      no_mx_lookups: true
deps/gen_smtp/src/gen_smtp_client.erl:    | {no_mx_lookups, boolean()}
deps/gen_smtp/src/gen_smtp_client.erl:                case proplists:get_value(no_mx_lookups, NewOptions) of
deps/gen_smtp/src/gen_smtp_client.erl:        case proplists:get_value(no_mx_lookups, Options) of
diff --git a/config/runtime.exs b/config/runtime.exs
index 8599521..1ae181e 100644
--- a/config/runtime.exs
+++ b/config/runtime.exs
@@ -79,6 +79,7 @@ if config_env() == :prod do
           password = System.fetch_env!("MAILER_SMTP_PASSWORD")
           port = System.get_env("MAILER_SMTP_PORT", "587") |> maybe_to_int.()
           ssl? = System.get_env("MAILER_ENABLE_SSL", "FALSE") in [1, "1", "true", "TRUE"]
+

           starttls? =
             System.get_env("MAILER_ENABLE_STARTTLS", "FALSE") in [1, "1", "true", "TRUE"]
@@ -88,7 +89,8 @@ if config_env() == :prod do
             relay: host,
             username: user,
             password: password,
-            from_email: from_email
+            from_email: from_email,
+            no_mx_lookups: true
           ]
           |> put_if_not_empty.(:port, port)
           |> then(fn config ->
verymilan commented 1 week ago

update: i was able to change it directly in smtp.ex for now:

diff --git a/lib/keila/mailings/sender_adapters/smtp.ex b/lib/keila/mailings/sender_adapters/smtp.ex
index ab4a37f..6b61b91 100644
--- a/lib/keila/mailings/sender_adapters/smtp.ex
+++ b/lib/keila/mailings/sender_adapters/smtp.ex
@@ -32,7 +32,8 @@ defmodule Keila.Mailings.SenderAdapters.SMTP do
       username: config.smtp_username,
       password: config.smtp_password,
       auth: :always,
-      port: config.smtp_port
+      port: config.smtp_port,
+      no_mx_lookups: true
     ]
     |> maybe_put_tls_opts(config)
   end

hope it wont break this time and i'd still like to mention that Keila should not lookup MX records for sending emails. if anything it should be optional.