Skip to content

Commit

Permalink
Add Mailgun base_url sender config option
Browse files Browse the repository at this point in the history
  • Loading branch information
wmnnd committed Feb 10, 2024
1 parent 99d1001 commit c109ee2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Added new Gmail user agent to avoid tracking invalid clicks/opens
- Return to list of unsubscribed/unreachable contacts after delete action from
one of those pages. Implements #193 (thanks @digitalfredy for reporting)
- It's now possible to choose between the US and EU API endpoints for Mailgun senders (thanks @harryfear for reporting)

## Fixed
- Clicking "Delete all" on the contacts list no longer causes a server error
Expand Down
10 changes: 7 additions & 3 deletions lib/keila/mailings/sender_adapters/mailgun.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ defmodule Keila.Mailings.SenderAdapters.Mailgun do
@impl true
def name, do: "mailgun"

@base_url "https://api.mailgun.net/v3"

@impl true
def schema_fields do
[
mailgun_api_key: :string,
mailgun_domain: :string
mailgun_domain: :string,
mailgun_base_url: :string
]
end

@impl true
def changeset(changeset, params) do
changeset
|> cast(params, [:mailgun_api_key, :mailgun_domain])
|> cast(params, [:mailgun_api_key, :mailgun_domain, :mailgun_base_url])
|> validate_required([:mailgun_api_key, :mailgun_domain])
end

Expand All @@ -24,7 +27,8 @@ defmodule Keila.Mailings.SenderAdapters.Mailgun do
[
adapter: Swoosh.Adapters.Mailgun,
api_key: config.mailgun_api_key,
domain: config.mailgun_domain
domain: config.mailgun_domain,
base_url: config.mailgun_base_url || @base_url
]
end
end
15 changes: 15 additions & 0 deletions lib/keila_web/templates/sender/_mailgun_config.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@
<% end %>
</div>

<div class="form-row">
<%= label(@form, :mailgun_base_url, "Base URL") %>
<%= with_validation(@form, :mailgun_base_url) do %>
<%= select(
@form,
:mailgun_base_url,
[
"https://api.mailgun.net/v3",
"https://api.eu.mailgun.net/v3"
],
class: "text-black"
) %>
<% end %>
</div>

<%= if is_nil(input_value(@form, :mailgun_api_key)) do %>
<div class="form-row">
<%= label(@form, :mailgun_api_key, gettext("API Key")) %>
Expand Down

0 comments on commit c109ee2

Please sign in to comment.