Skip to content

Commit

Permalink
Add Campaign Monitor Adapter to available adapters (beam-community#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackmarchant authored and Damirados committed Jul 5, 2019
1 parent cea3fd4 commit db8a3a8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ add a new adapter to the list.
- `Bamboo.ConfigAdapter` - See [BinaryNoggin/bamboo_config_adapter](https://github.com/BinaryNoggin/bamboo_config_adapter) declare config at runtime.
- `Bamboo.MailgunAdapter` - Ships with Bamboo. Thanks to [@princemaple].
- `Bamboo.MailjetAdapter` - See [moxide/bamboo_mailjet](https://github.com/moxide/bamboo_mailjet).
- `Bamboo.CampaignMonitorAdapter` - See [jackmarchant/bamboo_campaign_monitor](https://github.com/jackmarchant/bamboo_campaign_monitor).
- `Bamboo.MandrillAdapter` - Ships with Bamboo.
- `Bamboo.SendGridAdapter` - Ships with Bamboo.
- `Bamboo.SMTPAdapter` - See [fewlinesco/bamboo_smtp](https://github.com/fewlinesco/bamboo_smtp).
Expand Down
12 changes: 6 additions & 6 deletions lib/bamboo/adapters/mailgun_adapter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ defmodule Bamboo.MailgunAdapter do
Sends email using Mailgun's API.
Use this adapter to send emails through Mailgun's API. Requires that an API
key and a domain are set in the config.
key, domain is pulled up from from field in mail.
## Example config
# In config/config.exs, or config.prod.exs, etc.
config :my_app, MyApp.Mailer,
adapter: Bamboo.MailgunAdapter,
api_key: "my_api_key" # or {:system, "MAILGUN_API_KEY"},
domain: "your.domain" # or {:system, "MAILGUN_DOMAIN"}
# Define a Mailer. Maybe in lib/my_app/mailer.ex
defmodule MyApp.Mailer do
Expand All @@ -30,7 +29,6 @@ defmodule Bamboo.MailgunAdapter do
def handle_config(config) do
config
|> Map.put(:api_key, get_setting(config, :api_key))
|> Map.put(:domain, get_setting(config, :domain))
end

defp get_setting(config, key) do
Expand Down Expand Up @@ -65,7 +63,7 @@ defmodule Bamboo.MailgunAdapter do
body = to_mailgun_body(email)
config = handle_config(config)

case :hackney.post(full_uri(config), headers(email, config), body, [:with_body]) do
case :hackney.post(full_uri(email), headers(email, config), body, [:with_body]) do
{:ok, status, _headers, response} when status > 299 ->
raise_api_error(@service_name, response, body)

Expand All @@ -80,9 +78,11 @@ defmodule Bamboo.MailgunAdapter do
@doc false
def supports_attachments?, do: true

defp full_uri(config) do
defp full_uri(%Email{from: {_, address}}) do
[_, domain] = String.split(address, "@")

Application.get_env(:bamboo, :mailgun_base_uri, @base_uri) <>
"/" <> config.domain <> "/messages"
"/" <> domain <> "/messages"
end

defp headers(%Email{} = email, config) do
Expand Down

0 comments on commit db8a3a8

Please sign in to comment.