-
Notifications
You must be signed in to change notification settings - Fork 2
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
Update to latest Carbon. Added support for attachments. #18
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
require "http" | ||
require "json" | ||
require "carbon" | ||
require "base64" | ||
require "./errors" | ||
require "./carbon_sendgrid_extensions" | ||
|
||
|
@@ -35,7 +36,6 @@ class Carbon::SendGridAdapter < Carbon::Adapter | |
end | ||
|
||
# :nodoc: | ||
# Used only for testing | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure why this said used only for testing 🤔 This method is how we send the email lol |
||
def params | ||
data = { | ||
"personalizations" => [personalizations], | ||
|
@@ -45,6 +45,7 @@ class Carbon::SendGridAdapter < Carbon::Adapter | |
"reply_to" => reply_to_params, | ||
"asm" => {"group_id" => 0, "groups_to_display" => [] of Int32}, | ||
"mail_settings" => {sandbox_mode: {enable: sandbox?}}, | ||
"attachments" => attachments, | ||
}.compact | ||
|
||
if asm_data = email.asm | ||
|
@@ -138,6 +139,19 @@ class Carbon::SendGridAdapter < Carbon::Adapter | |
].compact | ||
end | ||
|
||
private def attachments : Array(Hash(String, String)) | ||
files = [] of Hash(String, String) | ||
email.attachments.map do |attachment| | ||
case attachment | ||
in AttachFile, ResourceFile | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know what the difference between |
||
files.push({"content" => Base64.encode(File.read(attachment[:file_path])), "type" => attachment[:mime_type].to_s, "filename" => attachment[:file_name].to_s, "disposition" => "attachment"}) | ||
in AttachIO, ResourceIO | ||
files.push({"content" => Base64.encode(attachment[:io].to_s), "type" => attachment[:mime_type].to_s, "filename" => attachment[:file_name].to_s, "disposition" => "attachment"}) | ||
end | ||
end | ||
files | ||
end | ||
|
||
private def text_content : Hash(String, String)? | ||
body = email.text_body | ||
if body && !body.empty? | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Sendgrid API docs mention that attachments should be Base64.