diff --git a/shard.yml b/shard.yml index d31b7b1..67b96d6 100644 --- a/shard.yml +++ b/shard.yml @@ -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" diff --git a/spec/carbon_smtp_adapter_spec.cr b/spec/carbon_smtp_adapter_spec.cr index 8ec02dd..862d9a1 100644 --- a/spec/carbon_smtp_adapter_spec.cr +++ b/spec/carbon_smtp_adapter_spec.cr @@ -28,6 +28,25 @@ class TestEmail < BaseEmail header "Message-ID", "" 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 @@ -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 diff --git a/src/carbon/adapters/smtp_adapter.cr b/src/carbon/adapters/smtp_adapter.cr index 50587d2..8879538 100644 --- a/src/carbon/adapters/smtp_adapter.cr +++ b/src/carbon/adapters/smtp_adapter.cr @@ -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