Skip to content

Instantly share code, notes, and snippets.

@gauravsaini23
Created April 23, 2012 11:42
Show Gist options
  • Save gauravsaini23/2470368 to your computer and use it in GitHub Desktop.
Save gauravsaini23/2470368 to your computer and use it in GitHub Desktop.
Delay all mails in application
# 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