【问题标题】:Ruby ActionMailer. Sending to new emailRuby ActionMailer。发送到新电子邮件
【发布时间】:2017-10-26 04:35:49
【问题描述】:

我正在尝试在我的邮件程序中设置一种方法,以便在两周后发送电子邮件。我无法从数据库中提取创建的电子邮件并将其放入“mail(to: ...)”...如果我从控制台请求它,我可以发送电子邮件。

因此目标是,每次添加新位置时,都会在 14 天后向给定的电子邮件地址发送一封电子邮件。 这是我的应用程序/邮件。

class NotificationMailer < ApplicationMailer
    default from: "no-reply@xxx.com"

    def reminder(email)
        @email = email

        mail(to: @place.email,
            subject: "Reminder: your box is going to be picked up in fourteen days")
    end 
end

我的模型

class Place < ApplicationRecord
    belongs_to :user
    after_create :send_alert_email

    geocoded_by :address
    after_validation :geocode 

    validates :name, presence: true 
    validates :name, length: {minimum: 3,
     too_short: " %{count} or more characters are required."}
    validates :address, presence: true
    validates :phone, length: { is: 10}

    def send_alert_email
        NotificationMailer.reminder(self).deliver(wait: 1.hour)
    end 

end

感谢大家的帮助。

【问题讨论】:

  • 您是否尝试将NotificationMailer 的等待时间设置为 14 天?
  • 嘿!我打算只做几个小时的数学。我想我发现我的问题是在提交新地点时从数据库中提取电子邮件。

标签: ruby-on-rails email


【解决方案1】:

不应该吗?

def reminder(place)
    @place = place

    mail(to: @place.email,
        subject: "Reminder: your box is going to be picked up in fourteen days")
end 

而且不需要做数学,你可以使用wait: 14.days

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-26
    • 2014-12-31
    • 2011-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多