plausible / analytics

Simple, open source, lightweight (< 1 KB) and privacy-friendly web analytics alternative to Google Analytics.
https://plausible.io
GNU Affero General Public License v3.0
19.89k stars 1.06k forks source link

IPv6 (only) SMTP not working #4147

Closed DennisGlindhart closed 4 months ago

DennisGlindhart commented 4 months ago

Past Issues Searched

Issue is a Bug Report

Using official Plausible Cloud hosting or self-hosting?

Self-hosting

Describe the bug

When using IPv6-only SMTP-server Plausible cannot send mail and gives NX-domain bacause it only tries to connect to IPv4/inet, instead of IPv6/inet6 with fallback to IPv4/inet. (only AAAA-record is available)

Happens with both Bamboo.SMTPAdapter and Bamboo.Mua (MAILER_ADAPTER=Bamboo.Mua after update to 2.1)

Using Bamboo.SMTPAdapter IPv6 can be enabled with adding sockopts in config/runtime.exs (https://github.com/plausible/analytics/blob/c15ce1fa154f1226f07c3abddc77727d236c01d9/config/runtime.exs#L473)

-      no_mx_lookups: get_var_from_path_or_env(config_dir, "SMTP_MX_LOOKUPS_ENABLED") || true
+      no_mx_lookups: get_var_from_path_or_env(config_dir, "SMTP_MX_LOOKUPS_ENABLED") || true,
+      sockopts: [:inet6, {:ip, {0,0,0,0,0,0,0,0}}]

I have no IPv4 environment to test in, so I don't know if this patch stops IPv4 from working.

I have not found a workaround for Bamboo.Mua.

When using Bamboo.SMTPAdapter the following error is printed when sending a password-reset mail:

[error] Task #PID<0.4539.0> started from #PID<0.4538.0> terminating
** (ArgumentError) raise/1 and reraise/2 expect a module name, string or exception as the first argument, got: {:network_failure, ~c"smtp", {:error, :nxdomain}}
    (bamboo 2.3.0) lib/bamboo/strategies/task_supervisor_strategy.ex:25: anonymous fn/3 in Bamboo.TaskSupervisorStrategy.deliver_later/3
    (elixir 1.16.0) lib/task/supervised.ex:101: Task.Supervised.invoke_mfa/2
Function: #Function<0.95237244/0 in Bamboo.TaskSupervisorStrategy.deliver_later/3>
    Args: []

When using Bamboo.Mua the following error is printed when sending a password-reset mail:

[error] Task #PID<0.4396.0> started from #PID<0.4395.0> terminating
** (Mua.TransportError) non-existing domain
    (bamboo 2.3.0) lib/bamboo/strategies/task_supervisor_strategy.ex:25: anonymous fn/3 in Bamboo.TaskSupervisorStrategy.deliver_later/3
    (elixir 1.16.0) lib/task/supervised.ex:101: Task.Supervised.invoke_mfa/2
Function: #Function<0.95237244/0 in Bamboo.TaskSupervisorStrategy.deliver_later/3>
    Args: []

Expected behavior

Either:

Screenshots

No response

Environment

- OS:Linux
ruslandoga commented 4 months ago

đŸ‘‹ @DennisGlindhart

Thank you for trying out the new adapter! As a quick workaround you can mount a config override with inet6: true passed in transport options to Mua. This would make it try IPv6 first and fallback to IPv4

my_config.exs

import Config

config :plausible, Plausible.Mailer,
  transport_opts: [inet6: true]

docker-compose.yml

plausible:
  image: ghcr.io/plausible/community-edition:v2.1.0
+ volumes:
+   - ./my_config.exs:/app/my_config.exs

plausible-conf.env

+ EXTRA_CONFIG_PATH=/app/my_config.exs
ruslandoga commented 4 months ago

https://github.com/plausible/analytics/pull/4134 would make this automatic in CE.