Is there a simple way of telling Devise to send all email via delayed_job?
Alternatively, instead of using the Delayed::Mailer gem, you can quite easily implement and use your own ActionMailer "delivery method", one that...
Do something along the lines of:
# in config/application.rb
ActionMailer::Base.add_delivery_method :queued, Mail::QueuedDelivery
# in config/environment.rb (or one of the config/environments/*.rb files)
config.action_mailer.delivery_method = :queued # ie. Mail::QueuedDelivery
# 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 # class QueueDelivery
end # module Mail
The Delayed::Job you need to implement would then...
email = ::Email.find_by_id(email_id)
Mail::Message.new(email.message).deliver
That's it... hope this help!
I have no idea what Devise is but I guess it is third-party gem you don't want to modify. Try delayed_job_mailer. You can extend Devise mailers by monkey patching them to use delayed_job.
class SomeExistingMailer
include Delayed::Mailer
end
or if you want to send all app emails via delayed job by default:
# config/initializers/delayed_mailer.rb
class ActionMailer::Base
include Delayed::Mailer
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With