From d252c8f2c4b3a3b23c4ed958a871beb7dd6fa1cc Mon Sep 17 00:00:00 2001 From: "Adam St. John" Date: Sat, 19 Sep 2020 11:29:54 -0400 Subject: [PATCH] Enable inline attachments for mailgun. --- .gitignore | 1 + lib/bamboo/adapters/mailgun_adapter.ex | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index bb18dc22..8b3949f7 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ /.elixir_ls erl_crash.dump *.ez +.DS_Store diff --git a/lib/bamboo/adapters/mailgun_adapter.ex b/lib/bamboo/adapters/mailgun_adapter.ex index 10e2c529..fcaced4b 100644 --- a/lib/bamboo/adapters/mailgun_adapter.ex +++ b/lib/bamboo/adapters/mailgun_adapter.ex @@ -236,11 +236,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)a @internal_fields ~w(attachments)a