Created
April 23, 2012 11:42
-
-
Save gauravsaini23/2470368 to your computer and use it in GitHub Desktop.
Delay all mails in application
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 config/application.rb | |
ActionMailer::Base.add_delivery_method :queued, Mail::QueuedDelivery | |
# in config/environment.rb | |
config.action_mailer.delivery_method = :queued | |
# in lib/mail/queued_delivery.rb | |
module Mail | |
class QueuedDelivery | |
def initialize(values = {}) | |
# (optional) | |
end | |
def deliver!(mail) | |
email = Email.create!(:delivery_handler => mail.delivery_handler.name, :message => mail.to_s) | |
Delayed::Job.enqueue Jobs::Email::DeliverEmail.new(email.id) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment