Skip to content

Instantly share code, notes, and snippets.

@bonkydog
Created August 24, 2011 06:23
Show Gist options
  • Save bonkydog/1167417 to your computer and use it in GitHub Desktop.
Save bonkydog/1167417 to your computer and use it in GitHub Desktop.
Messagebus ActionMailer adapter
# in your environment file (for instance, production.rb)
MyAwesomeApp::Application.configure do
# ...lots of configuration...
config.action_mailer.delivery_method = Messagebus::Mailer.new(ENV['MESSAGEBUS_API_KEY'])
end
# lib/messagebus/mailer.rb
module Messagebus
class Mailer
def initialize(api_key)
@client = MessagebusRubyApi::Client.new(api_key)
end
attr_accessor :settings
def new(*settings)
self
end
def deliver!(message)
deliver(message)
end
private
def deliver(message)
@client.common_info = {:fromEmail => message.from.first}
message.to.each do |addressee|
m = {:toEmail => addressee, :subject => message.subject}
if message.multipart?
m[:plaintextBody] = message.text_part.body.to_s if message.text_part
m[:htmlBody] = message.html_part.body.to_s if message.html_part
else
m[:plaintextBody] = message.body.to_s
end
@client.add_message(m)
end
status = @client.flush
if status[:failureCount] && status[:failureCount] > 0
raise "Messagebus failure. failureCount=#{failureCount}, message=#{message.inspect}"
end
end
end
end
@maxwell
Copy link

maxwell commented Oct 5, 2011

ok it looks like it is now send_common_info

@bonkydog
Copy link
Author

bonkydog commented Oct 5, 2011

messagebus_ruby_api (0.4.0)

@maxwell
Copy link

maxwell commented Oct 5, 2011

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment