[英]Rails Runner or Rake task to send one-off email to registered users
I'd like to send a one off email to users and, being new-ish to ActionMailer , not sure how to approach a one-off like this? 我想向用户发送一次性电子邮件,而对于ActionMailer来说是新手,不知道如何处理一次性电子邮件吗? Rails Runner , a Rake task or maybe even the rails console on the production machine?!?
Rails Runner , Rake任务或生产机器上的Rails控制台 ?
Figure I'd add an action for it to user_mailer.rb
. 图我将为其添加一个操作到
user_mailer.rb
。 And create an accompanying view in app/views/user_mailer/
. 并在
app/views/user_mailer/
创建一个伴随视图。 Just not sure how to trigger it. 只是不确定如何触发它。 I'd like to grab a few users and send to them in batches.
我想吸引一些用户并批量发送给他们。 Happy to do this manually...as we stagger sending the messages over the next few days/weeks.
很高兴手动执行此操作...因为我们在接下来的几天/几周内交错发送邮件。
Appreciate any suggestions or advice. 感谢任何建议。
If you want to do this as automatedly as possible, I'd take a look at the whenever gem . 如果您想尽可能自动地执行此操作,那么我将看看everyth gem 。 It lets you automate rake (or runner) tasks as cron jobs.
它使您可以将耙(或赛跑者)任务自动化为cron作业。 You can add a script somewhere in
lib
that uses ActionMailer to generate the emails, and schedule when they're sent with whenever/cron. 您可以在
lib
中的某个位置添加脚本,该脚本使用ActionMailer生成电子邮件,并计划何时/何时发送电子邮件。
As far as sending in batches, I would do something like this: 至于批量发送,我会做这样的事情:
Users.find_each(:batch_size => n) do |m|
mail = UserMailer.new(m.email_address, message)
mail.deliver
end
Obviously, that's near-pseudocode, but hopefully it puts you on the right track? 显然,这几乎是伪代码,但希望它能使您走上正确的轨道?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.