Created
August 24, 2011 06:23
-
-
Save bonkydog/1167417 to your computer and use it in GitHub Desktop.
Messagebus ActionMailer adapter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Thanks for the info! What ref of the message_bus_api are you using? I am getting NoMethodError: undefined method `common_info=' for #MessagebusRubyApi::Client:0x106bde690 with the latest master.
ok it looks like it is now send_common_info
messagebus_ruby_api (0.4.0)
Thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yeah, Devise just uses ActionMailer like everything else.
It sends password reset emails just fine using this setup on gallerystar.com.
For testing we use the email_spec gem.