-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: sendgrid support for content_id (#691)
* Add support for content_id in SendgridAdapter Introduces support for content_id so that inline images in e-mails can be send and referenced from HTML content of the e-mail * refactor: remove negated is_nil to satisfy credo --------- Co-authored-by: Hubert Łępicki <[email protected]>
- Loading branch information
1 parent
66782dc
commit 7a878f4
Showing
2 changed files
with
60 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,7 +161,43 @@ defmodule Bamboo.SendGridAdapterTest do | |
%{ | ||
"type" => "text/plain", | ||
"filename" => "attachment.txt", | ||
"content" => "VGVzdCBBdHRhY2htZW50Cg==" | ||
"content" => "VGVzdCBBdHRhY2htZW50Cg==", | ||
"disposition" => "attachment" | ||
} | ||
] | ||
end | ||
|
||
test "deliver/2 sends from, html and text body, subject, headers and inline attachment" do | ||
email = | ||
[ | ||
from: {"From", "[email protected]"}, | ||
subject: "My Subject", | ||
text_body: "TEXT BODY", | ||
html_body: "HTML BODY <img src='cid:myimg' />" | ||
] | ||
|> new_email() | ||
|> Email.put_header("Reply-To", "[email protected]") | ||
|> Email.put_attachment(Path.join(__DIR__, "../../../support/attachment.txt"), content_id: "myimg") | ||
|
||
SendGridAdapter.deliver(email, @config) | ||
|
||
assert SendGridAdapter.supports_attachments?() | ||
assert_receive {:fake_sendgrid, %{params: params, req_headers: headers}} | ||
|
||
assert params["from"]["name"] == elem(email.from, 0) | ||
assert params["from"]["email"] == elem(email.from, 1) | ||
assert params["subject"] == email.subject | ||
assert Enum.member?(params["content"], %{"type" => "text/plain", "value" => email.text_body}) | ||
assert Enum.member?(params["content"], %{"type" => "text/html", "value" => email.html_body}) | ||
assert Enum.member?(headers, {"authorization", "Bearer #{@config[:api_key]}"}) | ||
|
||
assert params["attachments"] == [ | ||
%{ | ||
"type" => "text/plain", | ||
"filename" => "attachment.txt", | ||
"content" => "VGVzdCBBdHRhY2htZW50Cg==", | ||
"disposition" => "inline", | ||
"content_id" => "myimg" | ||
} | ||
] | ||
end | ||
|