问题
I am working on a project in rails where i have used pluck
@employees = Employee.where.not("status = ? AND strftime('%d/%m', date_of_birth) = ?", "Active" , date.strftime('%d/%m')).pluck(:email)
mail(to: @employees, subject: 'Birthday Invitation')
when i am sending email using Whenever gems,email is not going.I am getting Rake aborted error
so how may i send email to more emp.
回答1:
Try below code
mailer
def birthday_email
date = Date.today
@employees = Employee.where("status = ? AND strftime('%d/%m', date_of_birth) = ?", "Active" , date.strftime('%d/%m')).where("age > 21")
@employees.find_in_batches(batch_size: 20) do |group|
group.each { |emp| mail(to: emp.email, subject: 'Birthday Wishes'); sleep 3;}
sleep 5
end
end
来源:https://stackoverflow.com/questions/42873678/how-may-i-apply-sleep-functionality-on-array-in-ruby-on-rails