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

add MAILGUN_BASE_URI #2935

Merged
merged 2 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,10 @@ case mailer_adapter do
api_key: get_var_from_path_or_env(config_dir, "MAILGUN_API_KEY"),
domain: get_var_from_path_or_env(config_dir, "MAILGUN_DOMAIN")

if mailgun_base_uri = get_var_from_path_or_env(config_dir, "MAILGUN_BASE_URI") do
config :plausible, Plausible.Mailer, base_uri: mailgun_base_uri
end
Copy link
Contributor Author

@ruslandoga ruslandoga May 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm doing it this way because the alternatives either don't work:

config :plausible, Plausible.Mailer,
  adapter: Bamboo.MailgunAdapter,
  hackney_opts: [recv_timeout: :timer.seconds(10)],
  api_key: get_var_from_path_or_env(config_dir, "MAILGUN_API_KEY"),
  domain: get_var_from_path_or_env(config_dir, "MAILGUN_DOMAIN"),
  # if MAILGUN_BASE_URI is not set, `base_uri: nil` and it causes a runtime error during delivery
  # https://github.com/thoughtbot/bamboo/blob/53bd3929da6778ccf4ec7817070ec19f2b12b772/lib/bamboo/adapters/mailgun_adapter.ex#L63-L65
  # it would've worked if base_uri used `Application.get_env(:bamboo, :base_uri) || @default_base_uri` instead.
  base_uri: get_var_from_path_or_env(config_dir, "MAILGUN_BASE_URI")

Or require more maintenance:

config :plausible, Plausible.Mailer,
  adapter: Bamboo.MailgunAdapter,
  hackney_opts: [recv_timeout: :timer.seconds(10)],
  api_key: get_var_from_path_or_env(config_dir, "MAILGUN_API_KEY"),
  domain: get_var_from_path_or_env(config_dir, "MAILGUN_DOMAIN"),
  # this works now but would require us to keep an eye on newer api version and keep it up to date
  base_uri: get_var_from_path_or_env(config_dir, "MAILGUN_BASE_URI", "https://api.mailgun.net/v3")


"Bamboo.MandrillAdapter" ->
config :plausible, Plausible.Mailer,
adapter: Bamboo.MandrillAdapter,
Expand Down
17 changes: 17 additions & 0 deletions test/plausible/config_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@ defmodule Plausible.ConfigTest do
]
end

test "Bamboo.MailgunAdapter with custom MAILGUN_BASE_URI" do
env = [
{"MAILER_ADAPTER", "Bamboo.MailgunAdapter"},
{"MAILGUN_API_KEY", "some-mailgun-key"},
{"MAILGUN_DOMAIN", "example.com"},
{"MAILGUN_BASE_URI", "https://api.eu.mailgun.net/v3"}
]

assert get_in(runtime_config(env), [:plausible, Plausible.Mailer]) == [
adapter: Bamboo.MailgunAdapter,
hackney_opts: [recv_timeout: 10_000],
api_key: "some-mailgun-key",
domain: "example.com",
base_uri: "https://api.eu.mailgun.net/v3"
]
end

test "Bamboo.MandrillAdapter" do
env = [
{"MAILER_ADAPTER", "Bamboo.MandrillAdapter"},
Expand Down