First, I define a mailer method
class UserMailer < Devise::Mailer
# customize mail format
def user_feedback(opts={})
@v = "Hello"
@opts = opts
mail(:to => "xxx@gmail.com", :bcc => ["yyy@gmail.com"], :subject => "Test")
end
handle_asynchronously :user_feedback
end
And, I call this method in a request
class MailsController < ApplicationController
def feedback
options[:feedback_time] = Time.now.strftime("%Y%m%d %H:%M:%S")
UserMailer.user_feedback(options).deliver
end
end
Then, I start delay_job worker like this
rake jobs:workoff
Here is the log
[Worker(host:localhost.localdomain pid:2809)] Starting job worker
[Worker(host:localhost.localdomain pid:2809)] Job Delayed::PerformableMethod (id=11) RUNNING
[Worker(host:localhost.localdomain pid:2809)] No more jobs available. Exiting
[Worker(host:localhost.localdomain pid:2208)] Starting job worker
[Worker(host:localhost.localdomain pid:2208)] Job Class#user_feedback (id=1) RUNNING
[Worker(host:localhost.localdomain pid:2208)] Job Class#user_feedback (id=1) COMPLETED after 0.0819
[Worker(host:localhost.localdomain pid:2208)] Job Delayed::PerformableMethod (id=2) RUNNING
[Worker(host:localhost.localdomain pid:2208)] 1 jobs processed at 2.7340 j/s, 0 failed
[Worker(host:localhost.localdomain pid:2208)] No more jobs available. Exiting
All of these have done, but the mail is not sent!
Don't call .deliver and add a .delay before the method you are calling on UserMailer
See this: https://github.com/collectiveidea/delayed_job#rails-3-mailers
For example:
UserMailer.delay.user_feedback(options)