Created
March 23, 2011 09:01
-
-
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
This file contains hidden or 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
| # 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