lib/snails/mailer.rb in snails-0.5.4 vs lib/snails/mailer.rb in snails-0.5.5
- old
+ new
@@ -198,10 +198,21 @@
end
end
class MailgunBackend < Backend
+ class Attachment < StringIO
+ attr_reader :original_filename, :content_type, :path
+
+ def initialize(data, filename, content_type)
+ super(data)
+ @path = '' # path
+ @original_filename = filename
+ @content_type = content_type || 'application/octet-stream'
+ end
+ end
+
def initialize(api_key:, domain_name:)
# @key = api_key
@url = "https://api:#{api_key}@api.mailgun.net/v3/#{domain_name}/messages"
end
@@ -220,10 +231,12 @@
if data[:text].blank? && data[:html].blank?
raise ArgumentError, "Either text or html required"
end
if email[:attachments]
- data[:attachment] = email[:attachments].map { |att| att[:content] }
+ data[:attachment] = email[:attachments].map do |att|
+ Attachment.new(att[:content], att[:filename], att[:content_type])
+ end
end
resp = RestClient.post(@url, data)
return resp.code == 200 ? [resp.body, data[:to]] : nil
end
\ No newline at end of file