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

feat: Enable inline attachments for mailgun. #551

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/.elixir_ls
erl_crash.dump
*.ez
.DS_Store
9 changes: 8 additions & 1 deletion lib/bamboo/adapters/mailgun_adapter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,18 @@ defmodule Bamboo.MailgunAdapter do
Map.put(body, :attachments, attachment_data)
end

defp prepare_file(%Attachment{} = attachment) do
defp prepare_file(%Attachment{content_id: nil} = attachment) do
{"", attachment.data,
{"form-data", [{"name", ~s/"attachment"/}, {"filename", ~s/"#{attachment.filename}"/}]}, []}
end

# At the time of writing, Mailgun did not support clients specifying content id.
# Instead, they set the content id to be the given filename.
defp prepare_file(%Attachment{} = attachment) do
{"", attachment.data,
{"form-data", [{"name", ~s/"inline"/}, {"filename", ~s/"#{attachment.filename}"/}]}, []}
end

@mailgun_message_fields ~w(from to cc bcc subject text html template recipient-variables)a
@internal_fields ~w(attachments)a

Expand Down