Skip to content

Instantly share code, notes, and snippets.

@szimek
Created March 23, 2011 09:01
Show Gist options
  • Select an option

  • Save szimek/882814 to your computer and use it in GitHub Desktop.

Select an option

Save szimek/882814 to your computer and use it in GitHub Desktop.
Initial version - the idea is to make Mail::QueuedDelivery a proxy that takes original delivery_method as a parameter
# lib/mail/queued_delivery.rb
require 'mail'
module Delayed
class PerformableMail
attr_reader :mail
def initialize(mail)
@mail = mail
end
def display_name
"#{mail.class}:#{mail.object_id}"
end
def perform
mail.delivery_method.deliver!(mail)
end
end
end
module Mail
class QueuedDelivery < Sendmail
def deliver!(mail)
# Switch email delivery method to a non-queued version,
# but keep the custom settings if present
mail.delivery_method(:sendmail)
Delayed::Job.enqueue Delayed::PerformableMail.new(mail)
self
end
end
end
# config/application.rb
require Rails.root.join("lib/mail/queued_delivery")
ActionMailer::Base.add_delivery_method :queued, Mail::QueuedDelivery
# config/environments/production.rb
config.action_mailer.delivery_method = :queued
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment