diff --git a/src/carbon/attachment.cr b/src/carbon/attachment.cr new file mode 100644 index 0000000..de9da44 --- /dev/null +++ b/src/carbon/attachment.cr @@ -0,0 +1,7 @@ +module Carbon + alias AttachFile = NamedTuple(file_path: String, file_name: String?, mime_type: String?) + alias AttachIO = NamedTuple(io: IO, file_name: String, mime_type: String?) + alias ResourceFile = NamedTuple(file_path: String, cid: String, file_name: String?, mime_type: String?) + alias ResourceIO = NamedTuple(io: IO, cid: String, file_name: String, mime_type: String?) + alias Attachment = AttachFile | AttachIO | ResourceFile | ResourceIO +end diff --git a/src/carbon/email.cr b/src/carbon/email.cr index 45c3c63..93a4942 100644 --- a/src/carbon/email.cr +++ b/src/carbon/email.cr @@ -8,7 +8,7 @@ abstract class Carbon::Email abstract def from : Carbon::Address abstract def to : Array(Carbon::Address) - def_equals subject, from, to, cc, bcc, headers, text_body, html_body + def_equals subject, from, to, cc, bcc, headers, text_body, html_body, attachments # Set this value to `false` to prevent the email from # being delivered @@ -91,6 +91,18 @@ abstract class Carbon::Email end end + @attachments = [] of Carbon::Attachment + getter attachments + + macro attachment(value) + def attachments : Array(Carbon::Attachment) + {% if @type.methods.map(&.name).includes?("attachments".id) %} + previous_def + {% end %} + @attachments << {{value}} + end + end + {% for method in [:to, :cc, :bcc] %} macro {{ method.id }}(value) def {{ method.id }} : Array(Carbon::Address)