Sha256: 97242f1038a9b1005f69a4382a2dbbe6681c9ab3a6f7def6f8b3b6e42b7756f4

Contents?: true

Size: 1.05 KB

Versions: 15

Compression:

Stored size: 1.05 KB

Contents

# MailQueue
  
module ActionMailer
  class QueueMailer < Base
    
    class << self
    
      def method_missing(method_symbol, *parameters)#:nodoc:
        case method_symbol.id2name
          when /^deliver_([_a-z]\w*)\!/ then super(method_symbol, *parameters)
          when /^deliver_([_a-z]\w*)/ then 
            if Spree::Config[:use_mail_queue] # only use the queue if it's been enabled
              queue_mail($1, *parameters)
            else
              super(method_symbol, *parameters)
            end
          else super(method_symbol, *parameters)
        end
      end
    
      def queue_mail(method_name, *parameters)
        mail = new(method_name, *parameters).mail
        qmail = QueuedMail.new
        qmail.object = mail
        qmail.mailer = self.to_s

        qmail.save!
      end
    end
  end
end


class MailQueue < ActiveRecord::Base
   
  def MailQueue.process
    
    for qmail in QueuedMail.find(:all)
      
      mailer = qmail.mailer.constantize
      mailer.deliver(qmail.object)
      qmail.destroy
      
    end
  end

end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
spree-0.11.4 vendor/plugins/mail_queue/lib/mail_queue.rb
spree-0.11.3 vendor/plugins/mail_queue/lib/mail_queue.rb
spree-0.11.2 vendor/plugins/mail_queue/lib/mail_queue.rb
spree-0.11.1 vendor/plugins/mail_queue/lib/mail_queue.rb
spree-0.11.0 vendor/plugins/mail_queue/lib/mail_queue.rb
spree-0.10.2 vendor/plugins/mail_queue/lib/mail_queue.rb
spree-0.10.1 vendor/plugins/mail_queue/lib/mail_queue.rb
spree-0.10.0 vendor/plugins/mail_queue/lib/mail_queue.rb
spree-0.10.0.beta vendor/plugins/mail_queue/lib/mail_queue.rb
spree-enriquez-0.9.4 vendor/plugins/mail_queue/lib/mail_queue.rb
spree-0.9.4 vendor/plugins/mail_queue/lib/mail_queue.rb
spree-0.9.3 vendor/plugins/mail_queue/lib/mail_queue.rb
spree-0.9.2 vendor/plugins/mail_queue/lib/mail_queue.rb
spree-0.9.1 vendor/plugins/mail_queue/lib/mail_queue.rb
spree-0.9.0 vendor/plugins/mail_queue/lib/mail_queue.rb