我有并且admin_mailer
:
class AdminMailer < ActionMailer::Base
def send_message_to_all_users(user, subject, body, locale)
@user = user
@body = body
@locale = locale
mail(:to => user.email, :subject => subject)
end
end
在我对控制器用户的操作中:
def send_email_to_all_users
users = User.all
subject = params[:subject]
body = params[:body]
locale = params[:locale]
for user in users
User.delay(queue: "Email", priority: 20).send_message_to_all_users(user, subject, body, locale)
end
respond_to do |format|
.........
end
end
在我的模型中User
class User
include Mongoid::Document
include Mongoid::Timestamps::Created
.
.
.
#delayed jobs methods
def self.send_message_to_all_users(user, subject, body, locale)
AdminMailer.send_message_to_all_users(user, subject, body, locale).deliver
end
def deliver
sleep 15
end
end
邮件列表users
非常长,超过 20.000 个电子邮件帐户。
我的问题是,以这种方式发送带有大邮件列表的时事通讯是否正确,或者我可以以更好的方式完成这项任务。
谢谢!