lib/snails/mailer.rb in snails-0.5.2 vs lib/snails/mailer.rb in snails-0.5.3

- old
+ new

@@ -185,11 +185,11 @@ def deliver(email, options = {}) debug = @debug.nil? ? !Snails.env.production? : @debug # if debug isn't set, determine based on env resp, email = Tuktuk.deliver(email, debug: debug) if resp.is_a?(Tuktuk::Bounce) - puts "[#{to}] Email bounced! [#{resp.code}] #{resp.message}" + puts "[#{email[:to]}] Email bounced! [#{resp.code}] #{resp.message}" end return resp, email end @@ -199,12 +199,12 @@ end class MailgunBackend < Backend def initialize(api_key:, domain_name:) - @key = api_key - @url = "https://api.mailgun.net/v3/#{domain_name}/messages" + # @key = api_key + @url = "https://api:#{api_key}@api.mailgun.net/v3/#{domain_name}/messages" end def deliver(email, options = {}) raise "No body!" if email[:body].nil? @@ -219,12 +219,15 @@ if data[:text].blank? && data[:html].blank? raise ArgumentError, "Either text or html required" end - opts = { username: 'api', password: @key } - resp = Dagger.post(@url, data, opts) - resp.ok? ? [resp.data, data[:to]] : nil + if email[:attachments] + data[:attachment] = email[:attachments].map { |att| { att[:content] } + end + + resp = RestClient.post(@url, data) + resp.code == 200 ? [resp.body, data[:to]] : nil end end end \ No newline at end of file