安排在 rails 内发送电子邮件

schedule the sending of an email in rails

我需要在客户注册后3个月发送一封电子邮件,我正在使用gem交换程序,目前我在客户注册时发送一封电子邮件,但我需要同时进行。

您需要某种 gem 来执行 cron 作业,例如 whenever。或者直接使用常规 linux cron 到 运行 你的脚本,然后每天将它编程到 运行。

然后是检查用户注册时间的脚本:

User.where(sent_email: false).each do |user|
    if user.registered_date + 3.months < Time.now
        #send email
        user.update(sent_email:true)
    end
end