Skip to content

Commit

Permalink
Allow sending emails with just text or just html bodies. Fixes #14
Browse files Browse the repository at this point in the history
  • Loading branch information
jwoertink committed Oct 30, 2023
1 parent a989b6a commit 6349434
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
14 changes: 14 additions & 0 deletions spec/carbon_smtp_adapter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ class TestEmail < BaseEmail
header "Sender", "support@myapp.com"
end

class NoHtmlEmail < BaseEmail
from Carbon::Address.new("My App Name", "support@myapp.com")
to "fred@example.org"
subject "NoHtml Subject"
templates text
end

describe CarbonSmtpAdapter do
it "works" do
email = TestEmail.new
Expand All @@ -44,4 +51,11 @@ describe CarbonSmtpAdapter do
received_email.should match(/Content-Type: text\/html/)
received_email.should match(/X-Crystal-Version: 0\.27/)
end

it "sends with just text template" do
email = NoHtmlEmail.new
delivered = Carbon::SmtpAdapter.new.deliver_now(email)

delivered.should_not eq(nil)
end
end
1 change: 1 addition & 0 deletions spec/templates/no_html_email/text.ecr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hi
9 changes: 7 additions & 2 deletions src/carbon/adapters/smtp_adapter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,13 @@ class Carbon::SmtpAdapter < Carbon::Adapter
end
end

message email.text_body
message_html email.html_body
if text = email.text_body.presence
message(text)
end

if html = email.html_body.presence
message_html(html)
end
end
end

Expand Down

0 comments on commit 6349434

Please sign in to comment.