-
-
Save bonkydog/1167417 to your computer and use it in GitHub Desktop.
# 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 |
Ooops! I suppose that's not obvious.
Just set config.action_mailer.deliver_method in your environment file like this:
MyAwesomeApp::Application.configure do
... lotsa configuration settings...
config.action_mailer.delivery_method = Messagebus::Mailer.new(ENV['MESSAGEBUS_API_KEY'])
end
Thanks! Any idea if things like Devise mailer will pick up on this setting? Also, will the normal test deliveries Just Work™? :)
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.
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!
Are we supposed to subclass our Mailer classes with this, or can we point some sort of ActionMailer setting at this?