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

Attachments and Body Resources #20

Merged
merged 1 commit into from
Feb 9, 2024
Merged
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
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ license: MIT
dependencies:
carbon:
github: luckyframework/carbon
version: ">= 0.4.0"
version: ">= 0.5.0"
email:
github: arcage/crystal-email
version: ">= 0.7.0, < 0.8"
Expand Down
23 changes: 23 additions & 0 deletions spec/carbon_smtp_adapter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,25 @@ class TestEmail < BaseEmail
header "Message-ID", "<abc123@myapp.com>"
header "Return-Path", "support@myapp.com"
header "Sender", "support@myapp.com"
attachment hello
attachment bye

def hello
{
io: IO::Memory.new("Hello"),
file_name: "hello.txt",
mime_type: "text/plain",
}
end

def bye
{
io: IO::Memory.new("Bye"),
cid: "unique_bar@myapp.com",
file_name: "bye.txt",
mime_type: "text/plain",
}
end
end

class NoHtmlEmail < BaseEmail
Expand All @@ -50,6 +69,10 @@ describe CarbonSmtpAdapter do
received_email.should match(/Content-Type: text\/plain/)
received_email.should match(/Content-Type: text\/html/)
received_email.should match(/X-Crystal-Version: 0\.27/)
received_email.should match(/hello\.txt/)
received_email.should match(/SGVsbG8=/)
received_email.should match(/bye\.txt/)
received_email.should match(/Qnll/)
end

it "sends with just text template" do
Expand Down
13 changes: 13 additions & 0 deletions src/carbon/adapters/smtp_adapter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ class Carbon::SmtpAdapter < Carbon::Adapter
if html = email.html_body.presence
message_html(html)
end

email.attachments.each do |attachment|
case attachment
in AttachFile
attach(file_path: attachment[:file_path], file_name: attachment[:file_name], mime_type: attachment[:mime_type])
in AttachIO
attach(io: attachment[:io], file_name: attachment[:file_name], mime_type: attachment[:mime_type])
in ResourceFile
message_resource(file_path: attachment[:file_path], cid: attachment[:cid], file_name: attachment[:file_name], mime_type: attachment[:mime_type])
in ResourceIO
message_resource(io: attachment[:io], cid: attachment[:cid], file_name: attachment[:file_name], mime_type: attachment[:mime_type])
end
end
end
end

Expand Down
Loading